Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ConfigDefault = Config{ Next: nil, Timeout: 0, OnTimeout: nil, Errors: nil, }
ConfigDefault is the default configuration.
Functions ¶
func New ¶
New enforces a timeout for each incoming request. It replaces the request's context with one that has the configured deadline, which is exposed through c.Context(). Handlers can detect the timeout by listening on c.Context().Done() and return early.
When a timeout occurs, the middleware returns immediately with fiber.ErrRequestTimeout (or the result of OnTimeout if configured). The handler goroutine can continue safely, and resources are recycled when it finishes via the Abandon/ForceRelease mechanism.
Types ¶
type Config ¶
type Config struct {
// Next defines a function to skip this middleware.
// Optional. Default: nil
Next func(c fiber.Ctx) bool
// OnTimeout is executed when a timeout occurs.
// Optional. Default: nil (return fiber.ErrRequestTimeout)
OnTimeout fiber.Handler
// Errors defines custom errors that are treated as timeouts.
// Optional. Default: nil
Errors []error
// Timeout defines the timeout duration for all routes.
// Optional. Default: 0 (no timeout)
Timeout time.Duration
}
Config holds the configuration for the timeout middleware.
Click to show internal directories.
Click to hide internal directories.