recover

package
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package recover provides panic recovery utilities for HTTP handlers.

Contract:

  • if the response is still uncommitted, a recovered panic becomes a 500 Problem Details response
  • if headers or body bytes have already been committed, the middleware logs the panic and aborts the request instead of preserving a misleading partial success response

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Middleware

func Middleware() func(http.Handler) http.Handler

Middleware converts panics into RFC 9457 problem details responses when the response is still uncommitted. If the handler already committed headers or body bytes, the middleware logs the panic and aborts the request rather than preserving a misleading partial success response.

func New added in v2.1.0

func New(opts ...Option) func(http.Handler) http.Handler

New converts uncommitted panics into RFC 9457 problem details responses and logs them through a configurable logger. Once a response has been committed, recovery logs the panic and aborts the request instead of returning a partial success response.

Types

type Option added in v2.1.0

type Option func(*config)

Option customizes panic recovery logging.

func WithLogger added in v2.1.0

func WithLogger(log ports.Logger) Option

WithLogger routes panic logs to the provided logger.

func WithStackLogging added in v2.1.0

func WithStackLogging(enabled bool) Option

WithStackLogging controls whether panic stacks are added to logs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL