timeout

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 2, 2026 License: MIT Imports: 6 Imported by: 2

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

func New(h fiber.Handler, config ...Config) fiber.Handler

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.

Jump to

Keyboard shortcuts

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