Timeout Middleware

Timeout middleware is used to timeout at a long running operation within a predefined period.



Custom Configuration 🔗


e := echo.New()
  Skipper: Skipper,
  ErrorHandler: func(err error, e echo.Context) error {
      // you can handle your error here, the returning error will be 
      // passed down the middleware chain
      return err
  Timeout: 30*time.Second,

Configuration 🔗

// TimeoutConfig defines the config for Timeout middleware.
TimeoutConfig struct {
    // Skipper defines a function to skip middleware.
    Skipper Skipper
    // ErrorHandler defines a function which is executed for a timeout
    // It can be used to define a custom timeout error
    ErrorHandler TimeoutErrorHandlerWithContext
    // Timeout configures a timeout for the middleware, defaults to 0 for no timeout
    Timeout time.Duration

TimeoutErrorHandlerWithContext is responsible for handling the errors when a timeout happens

// TimeoutErrorHandlerWithContext is an error handler that is used 
// with the timeout middleware so we can handle the error 
// as we see fit
TimeoutErrorHandlerWithContext func(error, echo.Context) error

Default Configuration

DefaultTimeoutConfig = TimeoutConfig{
    Skipper:      DefaultSkipper,
    Timeout:      0,
    ErrorHandler: nil,