jweb

package module
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package web exposes public HTTP helpers for request binding, responses, and structured errors.

Index

Constants

View Source
const (
	BindSourceJSON  = binding.BindSourceJSON
	BindSourcePath  = binding.BindSourcePath
	BindSourceQuery = binding.BindSourceQuery
)
View Source
const (
	BindErrorMalformedBody   = binding.BindErrorMalformedBody
	BindErrorValidation      = binding.BindErrorValidation
	BindErrorUnsupportedType = binding.BindErrorUnsupportedType
	BindErrorInvalidParams   = binding.BindErrorInvalidParams
)

Variables

This section is empty.

Functions

func AbortError

func AbortError(c *gin.Context, err *errors.HTTPError)

AbortError aborts the request and writes a structured JSON error response.

func Accepted

func Accepted(c *gin.Context, body any)

Accepted writes a 202 JSON response.

func BadRequest

func BadRequest(message string) *errors.HTTPError

BadRequest creates a 400 HTTP error.

func BindJSON

func BindJSON[T any](c *gin.Context) (T, error)

BindJSON binds and validates a JSON request body.

func BindPath

func BindPath[T any](c *gin.Context) (T, error)

BindPath binds and validates path parameters.

func BindQuery

func BindQuery[T any](c *gin.Context) (T, error)

BindQuery binds and validates query parameters.

func Conflict

func Conflict(message string) *errors.HTTPError

Conflict creates a 409 HTTP error.

func Created

func Created(c *gin.Context, body any)

Created writes a 201 JSON response.

func Fail

func Fail(c *gin.Context, err *HTTPError)

func FailBind

func FailBind(c *gin.Context, err error)

func Forbidden

func Forbidden(message string) *errors.HTTPError

Forbidden creates a 403 HTTP error.

func InternalServerError

func InternalServerError(message string) *errors.HTTPError

InternalServerError creates a 500 HTTP error.

func Module

func Module() jelly.Module

func NewError

func NewError(status int, code string, message string) *errors.HTTPError

NewError creates a structured HTTP error with a custom status and code.

func NoContent

func NoContent(c *gin.Context)

NoContent writes a 204 response with no body.

func NotFound

func NotFound(message string) *errors.HTTPError

NotFound creates a 404 HTTP error.

func OK

func OK(c *gin.Context, body any)

OK writes a 200 JSON response.

func RegisterValidation

func RegisterValidation(tag string, fn validator.Func) error

RegisterValidation registers a custom validator tag for Jelly bindings.

func SetBindErrorEncoder

func SetBindErrorEncoder(encoder BindErrorEncoder)

func SetErrorRenderer

func SetErrorRenderer(renderer ErrorRenderer)

func SetHTTPErrorEncoder

func SetHTTPErrorEncoder(encoder HTTPErrorEncoder)

func Status

func Status(c *gin.Context, code int, body any)

Status writes a JSON response with the given status code.

func Unauthorized

func Unauthorized(message string) *errors.HTTPError

Unauthorized creates a 401 HTTP error.

Types

type BindError

type BindError = binding.BindError

type BindErrorEncoder

type BindErrorEncoder interface {
	EncodeBindError(err *BindError) ErrorPayload
}

type BindErrorKind

type BindErrorKind = binding.BindErrorKind

type BindSource

type BindSource = binding.BindSource

type ErrorPayload

type ErrorPayload struct {
	Code    string
	Message string
	Details any
}

type ErrorRenderer

type ErrorRenderer interface {
	RenderHTTPError(c *gin.Context, err *HTTPError)
	RenderBindError(c *gin.Context, err *BindError)
}

type FieldViolation

type FieldViolation = binding.FieldViolation

type HTTPError

type HTTPError = servererrors.HTTPError

type HTTPErrorEncoder

type HTTPErrorEncoder interface {
	EncodeHTTPError(err *HTTPError) ErrorPayload
}

type MiddlewareProvider

type MiddlewareProvider = internalweb.MiddlewareProvider

type RouteProvider

type RouteProvider = internalweb.RouteProvider

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL