fiberutils

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2026 License: MIT Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindJSON

func BindJSON[T any](c fiber.Ctx) (T, error)

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

func MiddlewareCtxTimeout(dur time.Duration) fiber.Handler

MiddlewareCtxTimeout bounds each request's context with a dur timeout, so downstream handlers and DB calls are cancelled when it elapses.

func MiddlewareLogger

func MiddlewareLogger() fiber.Handler

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

func MustWithSwagger(app *fiber.App, specYAML []byte)

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

func SendBadRequest(err error) error

SendBadRequest wraps err as a 400 Bad Request fiber error.

func SendUnprocessable

func SendUnprocessable(err error) error

SendUnprocessable wraps err as a 422 Unprocessable Entity fiber error.

func StatusFromContext

func StatusFromContext(c fiber.Ctx, err error) int

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

func WithSwagger(app *fiber.App, specYAML []byte) error

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

type StructValidator struct {
	Validator *validator.Validate
}

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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