Help us shape the future of Go! Take the 2026 Go Developer Survey

timeout

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExceeded = errors.New("timeout: request context deadline exceeded")

ErrExceeded identifies a downstream context deadline.

Functions

func Doc added in v0.7.1

func Doc() zinc.MiddlewareDoc

Doc describes the middleware for the OpenAPI spec: a request that runs past the deadline is answered with 503. Pass it to Document beside the middleware.

func New

func New(configs ...Config) zinc.Middleware

New installs Config.Timeout as the downstream request deadline. It does not run the handler in a detached goroutine, so cancellation remains idiomatic.

func Remaining

func Remaining(c *zinc.Context) (time.Duration, bool)

Remaining returns time until the installed deadline.

Types

type Config

type Config struct {
	Timeout      time.Duration
	ErrorHandler func(*zinc.Context, *Error) error
}

Config controls request deadline installation and mapping.

type Error

type Error struct {
	Info  Info
	Cause error
}

Error preserves deadline metadata and the underlying error.

func (*Error) Error

func (e *Error) Error() string

func (*Error) Is

func (e *Error) Is(target error) bool

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Info

type Info struct {
	Timeout  time.Duration
	Deadline time.Time
}

Info describes the request deadline installed by middleware.

func Get

func Get(c *zinc.Context) (Info, bool)

Get returns installed deadline metadata.

func MustGet

func MustGet(c *zinc.Context) Info

MustGet returns deadline metadata or panics when absent.

Jump to

Keyboard shortcuts

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