Recover
Recover 中间件会从链中任意位置的 panic 中恢复,打印堆栈跟踪,并把控制权传给集中式 HTTPErrorHandler。
所有核心中间件都位于 middleware 包中:
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}))上面的示例使用 StackSize 为 1 KB,并对 DisableStackAll 和 DisablePrintStack 使用默认值。
RecoverConfig · github.com/labstack/echo/v5@5196b9b
字段说明由英文源码注释生成。
| 字段 | 类型 | 说明 | 源码 |
|---|---|---|---|
Skipper | Skipper | Skipper defines a function to skip middleware. | L17 |
StackSize | int | Size of the stack to be printed. Optional. Default value 4KB. | L21 |
DisableStackAll | bool | DisableStackAll disables formatting stack traces of all other goroutines into buffer after the trace for the current goroutine. Optional. Default value false. | L26 |
DisablePrintStack | bool | DisablePrintStack disables printing stack trace. Optional. Default value as false. | L30 |
var DefaultRecoverConfig = RecoverConfig{ Skipper: DefaultSkipper, StackSize: 4 << 10, // 4 KB DisableStackAll: false, DisablePrintStack: false,}