Documentation
¶
Overview ¶
Package recover provides panic recovery middleware for the aarv framework.
It catches panics in downstream handlers, logs the stack trace, and returns a 500 JSON error response instead of crashing the server.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(config ...Config) aarv.Middleware
New creates a panic recovery middleware with optional configuration. If no config is provided, DefaultConfig is used.
Types ¶
type Config ¶
type Config struct {
// StackSize is the maximum size of the stack trace buffer in bytes.
// Default: 4096.
StackSize int
// DisableStackAll disables capturing the stack of all goroutines.
// When false (default), runtime.Stack is called with all=true.
DisableStackAll bool
// DisablePrintStack disables logging the stack trace.
// When true, the panic value is still logged but the stack trace is omitted.
DisablePrintStack bool
// Handler is an optional custom panic handler. When set, it is called
// instead of the default 500 JSON response. The handler receives the
// response writer, request, recovered panic value, and captured stack
// trace. Logging is still performed by the middleware unless
// DisablePrintStack is true.
Handler PanicHandler
}
Config holds configuration for the recovery middleware.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default recovery configuration.
type PanicHandler ¶ added in v0.4.4
PanicHandler is a callback invoked when a panic is recovered. It receives the response writer, request, recovered value, and stack trace. If set, it replaces the default 500 JSON response — the handler is responsible for writing the HTTP status and body.