Recover
O middleware Recover recupera panics em qualquer ponto da cadeia, imprime a stack trace e passa o controle para o HTTPErrorHandler centralizado.
Todo o middleware principal fica no pacote middleware:
import "github.com/labstack/echo/v5/middleware"e.Use(middleware.Recover())Configuração customizada
Seção intitulada “Configuração customizada”e := echo.New()e.Use(middleware.RecoverWithConfig(middleware.RecoverConfig{ StackSize: 1 << 10, // 1 KB}))O exemplo acima usa um StackSize de 1 KB e valores padrão para DisableStackAll e
DisablePrintStack.
Configuração
Seção intitulada “Configuração”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 the buffer after the trace for the current goroutine. // Optional. Default value false. DisableStackAll bool
// DisablePrintStack disables printing the stack trace. // Optional. Default value false. DisablePrintStack bool}Configuração padrão
Seção intitulada “Configuração padrão”var DefaultRecoverConfig = RecoverConfig{ Skipper: DefaultSkipper, StackSize: 4 << 10, // 4 KB DisableStackAll: false, DisablePrintStack: false,}