Skip to content

Recover

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

All core middleware lives in the middleware package:

import "github.com/labstack/echo/v5/middleware"
e.Use(middleware.Recover())
e := echo.New()
e.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{
StackSize: 1 << 10, // 1 KB
}))

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

RecoverConfig · github.com/labstack/echo/[email protected]

Fields from package source
FieldTypeDescriptionSource
SkipperSkipperSkipper defines a function to skip middleware.L17
StackSizeintSize of the stack to be printed. Optional. Default value 4KB.L21
DisableStackAllboolDisableStackAll disables formatting stack traces of all other goroutines into buffer after the trace for the current goroutine. Optional. Default value false.L26
DisablePrintStackboolDisablePrintStack disables printing stack trace. Optional. Default value as false.L30
Functions from package source
TypeSource
func Recover() echo.MiddlewareFuncL43
func RecoverWithConfig(config RecoverConfig) echo.MiddlewareFuncL48
var DefaultRecoverConfig = RecoverConfig{
Skipper: DefaultSkipper,
StackSize: 4 << 10, // 4 KB
DisableStackAll: false,
DisablePrintStack: false,
}