recovery

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(logger *slog.Logger, opts ...ConfigOption) gin.HandlerFunc

New returns a gin.HandlerFunc (middleware) that recovers from any panics and logs the panic using slog. It sets the HTTP status code to 500. By default, the log level is ERROR.

Types

type Config

type Config struct {
	// contains filtered or unexported fields
}

Config represents the recovery middleware configuration.

type ConfigOption

type ConfigOption func(*Config)

ConfigOption allows to customize the middleware config.

func WithCustomFields

func WithCustomFields(customFields CustomFields) ConfigOption

WithCustomFields allows to set a custom function to add custom fields to the log line.

func WithCustomRecovery

func WithCustomRecovery(customRecovery gin.RecoveryFunc) ConfigOption

WithCustomRecovery allows to set a custom recovery function.

func WithDefaultLevel

func WithDefaultLevel(level slog.Level) ConfigOption

WithDefaultLevel allows to set the default log level.

func WithoutDefaultFields

func WithoutDefaultFields() ConfigOption

WithoutDefaultFields to not use the default fields in the log line.

func WithoutError

func WithoutError() ConfigOption

WithoutError to not log the error field.

func WithoutRequest

func WithoutRequest() ConfigOption

WithoutRequest to not log the request field.

func WithoutStack

func WithoutStack() ConfigOption

WithoutStack to not log the stack field.

type CustomFields

type CustomFields func(c *gin.Context) []slog.Attr

CustomFields allows to add custom fields to the log line.

Jump to

Keyboard shortcuts

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