Documentation
¶
Overview ¶
Package fiberext provides a thin opinionated wrapper around fiber/v2, offering builder-style configuration, typed request helpers, and HTTP status response helpers.
Index ¶
- Variables
- func Accepted(ctx Context, obj ...any) error
- func AlreadyReported(ctx Context, obj ...any) error
- func BadGateway(ctx Context, obj ...any) error
- func BadRequest(ctx Context, obj ...any) error
- func Conflict(ctx Context, obj ...any) error
- func Continue(ctx Context) error
- func Created(ctx Context, obj ...any) error
- func EarlyHints(ctx Context) error
- func ExpectationFailed(ctx Context, obj ...any) error
- func FailedDependency(ctx Context, obj ...any) error
- func Forbidden(ctx Context, obj ...any) error
- func Found(ctx Context) error
- func FromBody[T any](ctx Context) (T, error)
- func FromParams[T any](ctx Context) (T, error)
- func FromQuery[T any](ctx Context) (T, error)
- func GatewayTimeout(ctx Context, obj ...any) error
- func GetParam(ctx Context, key string, def ...string) string
- func GetQueryArg(ctx Context, key string, def ...string) string
- func Gone(ctx Context, obj ...any) error
- func HTTPVersionNotSupported(ctx Context, obj ...any) error
- func IMUsed(ctx Context, obj ...any) error
- func InsufficientStorage(ctx Context, obj ...any) error
- func LengthRequired(ctx Context, obj ...any) error
- func Locked(ctx Context, obj ...any) error
- func LoopDetected(ctx Context, obj ...any) error
- func MethodNotAllowed(ctx Context, obj ...any) error
- func MisdirectedRequest(ctx Context, obj ...any) error
- func MovedPermanently(ctx Context) error
- func MultiStatus(ctx Context, obj ...any) error
- func MultipleChoices(ctx Context, obj ...any) error
- func NetworkAuthenticationRequired(ctx Context, obj ...any) error
- func NoContent(ctx Context) error
- func NonAuthoritativeInformation(ctx Context, obj ...any) error
- func NotAcceptable(ctx Context, obj ...any) error
- func NotExtended(ctx Context, obj ...any) error
- func NotFound(ctx Context, obj ...any) error
- func NotImplemented(ctx Context, obj ...any) error
- func NotModified(ctx Context) error
- func OK(ctx Context, obj ...any) error
- func PartialContent(ctx Context, obj ...any) error
- func PaymentRequired(ctx Context, obj ...any) error
- func PermanentRedirect(ctx Context) error
- func PreconditionFailed(ctx Context, obj ...any) error
- func PreconditionRequired(ctx Context, obj ...any) error
- func Processing(ctx Context) error
- func ProxyAuthRequired(ctx Context, obj ...any) error
- func RequestEntityTooLarge(ctx Context, obj ...any) error
- func RequestHeaderFieldsTooLarge(ctx Context, obj ...any) error
- func RequestTimeout(ctx Context, obj ...any) error
- func RequestURITooLong(ctx Context, obj ...any) error
- func RequestedRangeNotSatisfiable(ctx Context, obj ...any) error
- func ResetContent(ctx Context) error
- func Respond(ctx Context, code int, obj ...any) error
- func RespondError(ctx Context, code int, obj ...any) error
- func RespondInternalError(ctx Context, obj ...any) error
- func SeeOther(ctx Context) error
- func ServiceUnavailable(ctx Context, obj ...any) error
- func SwitchProxy(ctx Context) error
- func SwitchingProtocols(ctx Context) error
- func Teapot(ctx Context, obj ...any) error
- func TemporaryRedirect(ctx Context) error
- func TooEarly(ctx Context, obj ...any) error
- func TooManyRequests(ctx Context, obj ...any) error
- func Unauthorized(ctx Context, obj ...any) error
- func UnavailableForLegalReasons(ctx Context, obj ...any) error
- func UnprocessableEntity(ctx Context, obj ...any) error
- func UnsupportedMediaType(ctx Context, obj ...any) error
- func UpgradeRequired(ctx Context, obj ...any) error
- func UseProxy(ctx Context) error
- func VariantAlsoNegotiates(ctx Context, obj ...any) error
- type Config
- func (config *Config) URL() string
- func (config *Config) WithAppName(v string) *Config
- func (config *Config) WithBodyLimit(v int) *Config
- func (config *Config) WithCaseSensitive(v bool) *Config
- func (config *Config) WithCertFile(v string) *Config
- func (config *Config) WithCertificate(v tls.Certificate) *Config
- func (config *Config) WithClientCertFile(v string) *Config
- func (config *Config) WithClientCerts(v *x509.CertPool) *Config
- func (config *Config) WithColorScheme(v fiber.Colors) *Config
- func (config *Config) WithCompressedFileSuffix(v string) *Config
- func (config *Config) WithConcurrency(v int) *Config
- func (config *Config) WithController(controller *Controller) *Config
- func (config *Config) WithDisableDefaultContentType(v bool) *Config
- func (config *Config) WithDisableDefaultDate(v bool) *Config
- func (config *Config) WithDisableHeaderNormalizing(v bool) *Config
- func (config *Config) WithDisableKeepalive(v bool) *Config
- func (config *Config) WithDisablePreParseMultipartForm(v bool) *Config
- func (config *Config) WithDisableStartupMessage(v bool) *Config
- func (config *Config) WithETag(v bool) *Config
- func (config *Config) WithEnableIPValidation(v bool) *Config
- func (config *Config) WithEnablePrintRoutes(v bool) *Config
- func (config *Config) WithEnableSplittingOnParsers(v bool) *Config
- func (config *Config) WithEnableTrustedProxyCheck(v bool) *Config
- func (config *Config) WithErrorHandler(v ErrorHandler) *Config
- func (config *Config) WithGETOnly(v bool) *Config
- func (config *Config) WithHost(v string) *Config
- func (config *Config) WithIdleTimeout(v time.Duration) *Config
- func (config *Config) WithImmutable(v bool) *Config
- func (config *Config) WithJSONDecoder(v utils.JSONUnmarshal) *Config
- func (config *Config) WithJSONEncoder(v utils.JSONMarshal) *Config
- func (config *Config) WithKeyFile(v string) *Config
- func (config *Config) WithMiddleware(middleware Handler) *Config
- func (config *Config) WithMutualTLS(v bool) *Config
- func (config *Config) WithNetwork(v string) *Config
- func (config *Config) WithPassLocalsToViews(v bool) *Config
- func (config *Config) WithPort(v int) *Config
- func (config *Config) WithPrefork(v bool) *Config
- func (config *Config) WithProxyHeader(v string) *Config
- func (config *Config) WithReadBufferSize(v int) *Config
- func (config *Config) WithReadTimeout(v time.Duration) *Config
- func (config *Config) WithReduceMemoryUsage(v bool) *Config
- func (config *Config) WithRequestMethods(v []string) *Config
- func (config *Config) WithResource(resource *Resource) *Config
- func (config *Config) WithServerHeader(v string) *Config
- func (config *Config) WithStreamRequestBody(v bool) *Config
- func (config *Config) WithStrictRouting(v bool) *Config
- func (config *Config) WithTLS(v bool) *Config
- func (config *Config) WithTrustedProxies(v []string) *Config
- func (config *Config) WithUnescapePath(v bool) *Config
- func (config *Config) WithViews(v fiber.Views) *Config
- func (config *Config) WithViewsLayout(v string) *Config
- func (config *Config) WithWriteBufferSize(v int) *Config
- func (config *Config) WithWriteTimeout(v time.Duration) *Config
- func (config *Config) WithXMLEncoder(v utils.XMLMarshal) *Config
- type Context
- type Controller
- type ErrorHandler
- type Handler
- type Resource
- type Server
Constants ¶
This section is empty.
Variables ¶
var HealthCheckResource = NewResource(fiber.MethodGet, "/health", func(ctx Context) error { return OK(ctx, fiber.Map{ "status": "ok", }) })
Functions ¶
func AlreadyReported ¶
AlreadyReported responds with 208 Already Reported and serializes obj as JSON.
func BadGateway ¶
BadGateway responds with 502 Bad Gateway.
func BadRequest ¶
BadRequest responds with 400 Bad Request.
func ExpectationFailed ¶
ExpectationFailed responds with 417 Expectation Failed.
func FailedDependency ¶
FailedDependency responds with 424 Failed Dependency.
func FromParams ¶
FromParams parses URL parameters into T using the "params" struct tag.
func GatewayTimeout ¶
GatewayTimeout responds with 504 Gateway Timeout.
func GetQueryArg ¶
GetQueryArg returns the query argument for key, falling back to def if absent.
func HTTPVersionNotSupported ¶
HTTPVersionNotSupported responds with 505 HTTP Version Not Supported.
func InsufficientStorage ¶
InsufficientStorage responds with 507 Insufficient Storage.
func LengthRequired ¶
LengthRequired responds with 411 Length Required.
func LoopDetected ¶
LoopDetected responds with 508 Loop Detected.
func MethodNotAllowed ¶
MethodNotAllowed responds with 405 Method Not Allowed.
func MisdirectedRequest ¶
MisdirectedRequest responds with 421 Misdirected Request.
func MovedPermanently ¶
MovedPermanently responds with 301 Moved Permanently.
func MultiStatus ¶
MultiStatus responds with 207 Multi-Status and serializes obj as JSON.
func MultipleChoices ¶
MultipleChoices responds with 300 Multiple Choices and serializes obj as JSON.
func NetworkAuthenticationRequired ¶
NetworkAuthenticationRequired responds with 511 Network Authentication Required.
func NonAuthoritativeInformation ¶
NonAuthoritativeInformation responds with 203 and serializes obj as JSON.
func NotAcceptable ¶
NotAcceptable responds with 406 Not Acceptable.
func NotExtended ¶
NotExtended responds with 510 Not Extended.
func NotImplemented ¶
NotImplemented responds with 501 Not Implemented.
func PartialContent ¶
PartialContent responds with 206 Partial Content and serializes obj as JSON.
func PaymentRequired ¶
PaymentRequired responds with 402 Payment Required.
func PermanentRedirect ¶
PermanentRedirect responds with 308 Permanent Redirect.
func PreconditionFailed ¶
PreconditionFailed responds with 412 Precondition Failed.
func PreconditionRequired ¶
PreconditionRequired responds with 428 Precondition Required.
func ProxyAuthRequired ¶
ProxyAuthRequired responds with 407 Proxy Authentication Required.
func RequestEntityTooLarge ¶
RequestEntityTooLarge responds with 413 Request Entity Too Large.
func RequestHeaderFieldsTooLarge ¶
RequestHeaderFieldsTooLarge responds with 431 Request Header Fields Too Large.
func RequestTimeout ¶
RequestTimeout responds with 408 Request Timeout.
func RequestURITooLong ¶
RequestURITooLong responds with 414 Request-URI Too Long.
func RequestedRangeNotSatisfiable ¶
RequestedRangeNotSatisfiable responds with 416 Range Not Satisfiable.
func ResetContent ¶
ResetContent responds with 205 Reset Content.
func RespondError ¶
RespondError writes status, optionally serializes obj, and returns a fiber.Error.
func RespondInternalError ¶
RespondInternalError responds with 500 Internal Server Error.
func ServiceUnavailable ¶
ServiceUnavailable responds with 503 Service Unavailable.
func SwitchingProtocols ¶
SwitchingProtocols responds with 101 Switching Protocols.
func TemporaryRedirect ¶
TemporaryRedirect responds with 307 Temporary Redirect.
func TooManyRequests ¶
TooManyRequests responds with 429 Too Many Requests.
func Unauthorized ¶
Unauthorized responds with 401 Unauthorized.
func UnavailableForLegalReasons ¶
UnavailableForLegalReasons responds with 451 Unavailable For Legal Reasons.
func UnprocessableEntity ¶
UnprocessableEntity responds with 422 Unprocessable Entity.
func UnsupportedMediaType ¶
UnsupportedMediaType responds with 415 Unsupported Media Type.
func UpgradeRequired ¶
UpgradeRequired responds with 426 Upgrade Required.
func VariantAlsoNegotiates ¶
VariantAlsoNegotiates responds with 506 Variant Also Negotiates.
Types ¶
type Config ¶
type Config struct {
fiber.Config
Host string `json:"host"`
Port int `json:"port"`
TLS bool `json:"useTls"`
MutualTLS bool
CertFile string
KeyFile string
ClientCertFile string
Certificate *tls.Certificate
ClientCerts *x509.CertPool
Controllers []*Controller
Resources []*Resource
Middlewares []Handler
}
Config extends fiber.Config with server address, TLS, and routing fields.
func NewConfig ¶
func NewConfig() *Config
NewConfig returns a zero-value Config ready for builder-style configuration.
func (*Config) WithAppName ¶
WithAppName sets the application name.
func (*Config) WithBodyLimit ¶
WithBodyLimit sets the maximum accepted request body size in bytes.
func (*Config) WithCaseSensitive ¶
WithCaseSensitive enables case-sensitive route matching.
func (*Config) WithCertFile ¶
WithCertFile sets the path to the TLS certificate file.
func (*Config) WithCertificate ¶
func (config *Config) WithCertificate(v tls.Certificate) *Config
WithCertificate sets an in-memory TLS certificate.
func (*Config) WithClientCertFile ¶
WithClientCertFile sets the path to the client CA certificate file for mTLS.
func (*Config) WithClientCerts ¶
WithClientCerts sets the client CA pool for mutual TLS.
func (*Config) WithColorScheme ¶
WithColorScheme sets a custom color scheme for startup messages.
func (*Config) WithCompressedFileSuffix ¶
WithCompressedFileSuffix sets the suffix appended to compressed static files.
func (*Config) WithConcurrency ¶
WithConcurrency sets the maximum number of concurrent connections.
func (*Config) WithController ¶
func (config *Config) WithController(controller *Controller) *Config
WithController appends controller to the list of route groups.
func (*Config) WithDisableDefaultContentType ¶
WithDisableDefaultContentType omits the default Content-Type response header.
func (*Config) WithDisableDefaultDate ¶
WithDisableDefaultDate omits the default Date response header.
func (*Config) WithDisableHeaderNormalizing ¶
WithDisableHeaderNormalizing disables automatic header name normalization.
func (*Config) WithDisableKeepalive ¶
WithDisableKeepalive disables keep-alive connections.
func (*Config) WithDisablePreParseMultipartForm ¶
WithDisablePreParseMultipartForm skips automatic multipart form parsing.
func (*Config) WithDisableStartupMessage ¶
WithDisableStartupMessage suppresses the Fiber ASCII banner on start.
func (*Config) WithEnableIPValidation ¶
WithEnableIPValidation enables validation of IP addresses returned by c.IP().
func (*Config) WithEnablePrintRoutes ¶
WithEnablePrintRoutes prints all registered routes on startup.
func (*Config) WithEnableSplittingOnParsers ¶
WithEnableSplittingOnParsers splits comma-separated query/body/header values.
func (*Config) WithEnableTrustedProxyCheck ¶
WithEnableTrustedProxyCheck enables trusted proxy header validation.
func (*Config) WithErrorHandler ¶
func (config *Config) WithErrorHandler(v ErrorHandler) *Config
WithErrorHandler sets the fiber error handler.
func (*Config) WithGETOnly ¶
WithGETOnly rejects all non-GET requests when true.
func (*Config) WithIdleTimeout ¶
WithIdleTimeout sets the keep-alive idle timeout.
func (*Config) WithImmutable ¶
WithImmutable makes request values immutable after the handler returns.
func (*Config) WithJSONDecoder ¶
func (config *Config) WithJSONDecoder(v utils.JSONUnmarshal) *Config
WithJSONDecoder sets a custom JSON unmarshal function.
func (*Config) WithJSONEncoder ¶
func (config *Config) WithJSONEncoder(v utils.JSONMarshal) *Config
WithJSONEncoder sets a custom JSON marshal function.
func (*Config) WithKeyFile ¶
WithKeyFile sets the path to the TLS private key file.
func (*Config) WithMiddleware ¶
WithMiddleware appends middleware to the global middleware chain.
func (*Config) WithMutualTLS ¶
WithMutualTLS enables or disables mutual TLS (client certificate verification).
func (*Config) WithNetwork ¶
WithNetwork sets the network type ("tcp", "tcp4", "tcp6").
func (*Config) WithPassLocalsToViews ¶
WithPassLocalsToViews passes fiber.Ctx locals to the template engine.
func (*Config) WithPrefork ¶
WithPrefork enables or disables multi-process prefork mode.
func (*Config) WithProxyHeader ¶
WithProxyHeader sets the header used by c.IP() when behind a proxy.
func (*Config) WithReadBufferSize ¶
WithReadBufferSize sets the per-connection read buffer size in bytes.
func (*Config) WithReadTimeout ¶
WithReadTimeout sets the deadline for reading the full request.
func (*Config) WithReduceMemoryUsage ¶
WithReduceMemoryUsage trades higher CPU usage for lower memory consumption.
func (*Config) WithRequestMethods ¶
WithRequestMethods sets the list of accepted HTTP methods.
func (*Config) WithResource ¶
WithResource appends resource as a top-level route.
func (*Config) WithServerHeader ¶
WithServerHeader sets the value of the Server response header.
func (*Config) WithStreamRequestBody ¶
WithStreamRequestBody enables request body streaming.
func (*Config) WithStrictRouting ¶
WithStrictRouting treats /foo and /foo/ as distinct routes when true.
func (*Config) WithTrustedProxies ¶
WithTrustedProxies sets the list of trusted proxy IP addresses.
func (*Config) WithUnescapePath ¶
WithUnescapePath unescapes encoded characters in the route path.
func (*Config) WithViewsLayout ¶
WithViewsLayout sets the global layout template name.
func (*Config) WithWriteBufferSize ¶
WithWriteBufferSize sets the per-connection write buffer size in bytes.
func (*Config) WithWriteTimeout ¶
WithWriteTimeout sets the deadline for writing the response.
func (*Config) WithXMLEncoder ¶
func (config *Config) WithXMLEncoder(v utils.XMLMarshal) *Config
WithXMLEncoder sets a custom XML marshal function.
type Controller ¶
Controller groups Resources under a common path prefix.
func NewController ¶
func NewController(path string) *Controller
NewController returns a Controller rooted at path.
func (*Controller) AddNewResource ¶
func (controller *Controller) AddNewResource(method, path string, handler Handler) *Controller
AddNewResource creates a Resource from method, path and handler and appends it.
func (*Controller) AddResource ¶
func (controller *Controller) AddResource(resource *Resource) *Controller
AddResource appends resource to the controller.
type ErrorHandler ¶
type ErrorHandler = fiber.ErrorHandler
ErrorHandler is an alias for fiber.ErrorHandler.
type Resource ¶
type Resource struct {
Method string
Path string
Handler Handler
Static bool
WebPath string
FilePath string
StaticConfig fiber.Static
}
Resource is a single route binding.
func NewResource ¶
NewResource returns a Resource for the given HTTP method, path and handler.