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 ¶
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
Click to show internal directories.
Click to hide internal directories.