recovery

package
v0.9.6 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: BSD-3-Clause Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

Handler implements http.Handler interface that will recover from panic and return appropriate HTTP response, log and notify on such event.

func New

func New(handler http.Handler, options ...Option) (h *Handler)

New creates a new Handler from the handler that is wrapped and protected with recover function.

func (Handler) ServeHTTP

func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler interface.

type Notifier

type Notifier interface {
	Notify(subject, body string) error
}

Notifier defines functionalities required for sending notifications.

type NotifierFunc

type NotifierFunc func(subject, body string) error

NotifierFunc type is an adapter to allow the use of ordinary functions as Notifier.

func (NotifierFunc) Notify

func (f NotifierFunc) Notify(subject, body string) error

Notify calls NotifierFunc(subject, body).

type Option

type Option func(*Handler)

Option is a function that sets optional parameters to the Handler.

func WithLabel

func WithLabel(label string) Option

WithLabel sets a string that will be included in log message and notification. Usually, it contains the name of the server and its version.

func WithLogger added in v0.8.0

func WithLogger(l *slog.Logger) Option

WithLogger sets the function that will perform message logging. Default is slog.Default().

func WithNotifier

func WithNotifier(notifier Notifier) Option

WithNotifier sets the function that takes subject and body arguments and is intended for sending notifications.

func WithPanicResponse

func WithPanicResponse(body, contentType string) Option

WithPanicResponse sets a fixed body and its content type HTTP header that will be returned as HTTP response on panic event. If WithPanicResponseHandler is defined, this options are ignored.

func WithPanicResponseHandler

func WithPanicResponseHandler(h http.Handler) Option

WithPanicResponseHandler sets http.Handler that will be executed on panic event. It is useful when the response has dynamic content. If the content is static it is better to use WithPanicResponse option instead. This option has a precedence upon WithPanicResponse.

Jump to

Keyboard shortcuts

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