httphandlers

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 24, 2021 License: BSD-2-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RecoveryHandler

func RecoveryHandler(opts ...RecoveryOption) func(h http.Handler) http.Handler

RecoveryHandler is HTTP middleware that recovers from a panic, logs the panic, writes http.StatusInternalServerError, and continues to the next handler.

Example:

r := mux.NewRouter()
r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
	panic("Unexpected error!")
})

http.ListenAndServe(":1123", handlers.RecoveryHandler()(r))

Types

type RecoveryHandlerLogger

type RecoveryHandlerLogger interface {
	Println(...interface{})
}

RecoveryHandlerLogger is an interface used by the recovering handler to print logs.

type RecoveryOption

type RecoveryOption func(http.Handler)

RecoveryOption provides a functional approach to define configuration for a handler; such as setting the logging whether or not to print strack traces on panic.

func PrintRecoveryStack

func PrintRecoveryStack(print bool) RecoveryOption

PrintRecoveryStack is a functional option to enable or disable printing stack traces on panic.

func RecoveryLogger

func RecoveryLogger(logger RecoveryHandlerLogger) RecoveryOption

RecoveryLogger is a functional option to override the default logger

Jump to

Keyboard shortcuts

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