Skip to content

Context Timeout

Context Timeout middleware applies a timeout to the request context within a predefined period, so context-aware methods can return early once the deadline is exceeded.

All core middleware lives in the middleware package:

import "github.com/labstack/echo/v5/middleware"
e.Use(middleware.ContextTimeout(60 * time.Second))
e.Use(middleware.ContextTimeoutWithConfig(middleware.ContextTimeoutConfig{
Timeout: 60 * time.Second,
}))

ContextTimeoutConfig · github.com/labstack/echo/v5@5196b9b

Fields from package source
FieldTypeDescriptionSource
Skipper Skipper Skipper defines a function to skip middleware. L17
ErrorHandler func(c *echo.Context, err error) error ErrorHandler is a function when error arises in middeware execution. L20
Timeout time.Duration Timeout configures a timeout for the middleware L23
Functions from package source
TypeSource
func ContextTimeout(timeout time.Duration) echo.MiddlewareFunc L28
func ContextTimeoutWithConfig(config ContextTimeoutConfig) echo.MiddlewareFunc L33
// Effective defaults applied when fields are left unset (Timeout is required).
ContextTimeoutConfig{
Skipper: DefaultSkipper,
}