Documentation
¶
Overview ¶
Package timeout provides an HTTP middleware that enforces a per-request timeout on downstream handler execution. When the timeout elapses, the context is cancelled and a 503 Service Unavailable response is returned.
Usage:
srv.Use(timeout.Middleware(30 * time.Second))
// or with a custom timeout response:
srv.Use(timeout.Middleware(30 * time.Second,
timeout.WithStatus(http.StatusGatewayTimeout),
))
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Middleware ¶
func Middleware(defaultTimeout time.Duration, opts ...Option) httpPlugin.Middleware
Middleware returns a httpPlugin.Middleware that enforces a timeout on downstream handler execution. If the handler does not complete within the timeout, the context is cancelled and a timeout error response is sent.
Types ¶
type Option ¶
type Option func(*options)
Option configures the timeout middleware.
func WithMessage ¶
WithMessage sets the response body text returned when the timeout fires. Default: "Service Unavailable".
func WithSkipFunc ¶
WithSkipFunc sets a function that returns true for requests that should bypass the timeout (e.g. long-polling or streaming endpoints).
func WithStatus ¶
WithStatus sets the HTTP status code returned when the timeout fires. Default: 503 Service Unavailable.