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

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

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

Configuration

  1. RecoverConfig struct {
  2. // Skipper defines a function to skip middleware.
  3. Skipper Skipper
  4. // Size of the stack to be printed.
  5. // Optional. Default value 4KB.
  6. StackSize int `json:"stack_size"`
  7. // DisableStackAll disables formatting stack traces of all other goroutines
  8. // into buffer after the trace for the current goroutine.
  9. // Optional. Default value false.
  10. DisableStackAll bool `json:"disable_stack_all"`
  11. // DisablePrintStack disables printing stack trace.
  12. // Optional. Default value as false.
  13. DisablePrintStack bool `json:"disable_print_stack"`
  14. }

Default Configuration

  1. DefaultRecoverConfig = RecoverConfig{
  2. Skipper: DefaultSkipper,
  3. StackSize: 4 << 10, // 4 KB
  4. DisableStackAll: false,
  5. DisablePrintStack: false,
  6. }