Recover 中间件从 panic 链中的任意位置恢复程序, 打印堆栈的错误信息,并将错误集中交给 HTTPErrorHandler 处理。
使用
e.Use(middleware.Recover())
e := echo.New() e.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{ StackSize: 1 << 10, // 1 KB }))
上面的示例使用 1 kb 的 StackSize,DisableStackAll 和 DisablePrintStack 使用默认值。
StackSize
DisableStackAll
DisablePrintStack
RecoverConfig struct { // Skipper defines a function to skip middleware. Skipper Skipper // Size of the stack to be printed. // Optional. Default value 4KB. StackSize int `json:"stack_size"` // DisableStackAll disables formatting stack traces of all other goroutines // into buffer after the trace for the current goroutine. // Optional. Default value false. DisableStackAll bool `json:"disable_stack_all"` // DisablePrintStack disables printing stack trace. // Optional. Default value as false. DisablePrintStack bool `json:"disable_print_stack"` }
默认配置
DefaultRecoverConfig = RecoverConfig{ Skipper: defaultSkipper, StackSize: 4 << 10, // 4 KB DisableStackAll: false, DisablePrintStack: false, }
Copyright© 2013-2020
All Rights Reserved 京ICP备2023019179号-8