Skip to main content

Recover

Recover middleware recovers from panics anywhere in the chain, prints stack trace and handles the control to the centralized HTTPErrorHandler.

Usage

e.Use(middleware.Recover())

Custom Configuration

Usage

e := echo.New()
e.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{
StackSize: 1 << 10, // 1 KB
}))

Example above uses a StackSize of 1 KB and default values for DisableStackAll and DisablePrintStack.

Configuration

type RecoverConfig struct {
// Skipper defines a function to skip middleware.
Skipper Skipper

// Size of the stack to be printed.
// Optional. Default value 4KB.
StackSize int

// DisableStackAll disables formatting stack traces of all other goroutines
// into buffer after the trace for the current goroutine.
// Optional. Default value false.
DisableStackAll bool

// DisablePrintStack disables printing stack trace.
// Optional. Default value as false.
DisablePrintStack bool
}

Default Configuration

var DefaultRecoverConfig = RecoverConfig{
Skipper: DefaultSkipper,
StackSize: 4 << 10, // 4 KB
DisableStackAll: false,
DisablePrintStack: false,
}