Documentation
¶
Index ¶
- func BindJSON[T any](c fiber.Ctx) (T, error)
- func ErrHandler() fiber.ErrorHandler
- func MiddlewareCtxTimeout(dur time.Duration) fiber.Handler
- func MiddlewareLogger() fiber.Handler
- func MustWithSwagger(app *fiber.App, specYAML []byte)
- func SendBadRequest(err error) error
- func SendUnprocessable(err error) error
- func StatusFromContext(c fiber.Ctx, err error) int
- func WithSwagger(app *fiber.App, specYAML []byte) error
- type StructValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BindJSON ¶
BindJSON decodes the request body into T. On failure it returns the zero T and a 422 Unprocessable Entity fiber error (already suitable for returning from a handler).
func ErrHandler ¶
func ErrHandler() fiber.ErrorHandler
ErrHandler returns a fiber error handler that logs the error (at error level with a stack for 5xx, warn for 4xx) and writes a JSON {"error": ...} body with the resolved status code.
func MiddlewareCtxTimeout ¶
MiddlewareCtxTimeout bounds each request's context with a dur timeout, so downstream handlers and DB calls are cancelled when it elapses.
func MiddlewareLogger ¶
MiddlewareLogger injects a request-scoped logger (with ip, method+path and user-agent fields) into the context and logs one debug line per request with latency, status code and request/response sizes.
func MustWithSwagger ¶ added in v1.0.1
MustWithSwagger is like WithSwagger but panics if specYAML cannot be parsed. Intended for wiring routes at startup with a spec embedded at compile time.
func SendBadRequest ¶
SendBadRequest wraps err as a 400 Bad Request fiber error.
func SendUnprocessable ¶
SendUnprocessable wraps err as a 422 Unprocessable Entity fiber error.
func StatusFromContext ¶
StatusFromContext resolves the HTTP status for a handler result: the actual response code when err is nil, the code of a *fiber.Error, or 500 otherwise.
func WithSwagger ¶
WithSwagger registers documentation routes on app from an OpenAPI spec given as YAML: /openapi.yaml (the spec verbatim), /openapi.json (the spec converted to JSON) and /docs (the embedded Swagger UI page). It returns an error if specYAML is not valid YAML.
Types ¶
type StructValidator ¶
StructValidator adapts a go-playground validator to fiber's StructValidator interface so bound structs are validated automatically.
func NewDefaultStructValidator ¶
func NewDefaultStructValidator() *StructValidator
NewDefaultStructValidator returns a StructValidator with required-struct validation enabled, ready to assign to fiber.Config.StructValidator.
func (*StructValidator) Validate ¶
func (v *StructValidator) Validate(out any) error
Validate validates out using the underlying validator, returning its error.