Documentation
¶
Overview ¶
Package recovery implements a middleware around panic recovery.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewMiddleware ¶
NewMiddleware returns a middleware that recovers from [panic]. It's best when used as global & first middleware, as it thus catches any [panic] down the chain.
Example ¶
package main
import (
"net/http"
"codeberg.org/kema/kmicro/pkg/http/middleware/recovery"
"codeberg.org/kema/kmicro/pkg/http/router"
)
func main() {
r := router.New()
r.Use(recovery.NewMiddleware())
// curl localhost:8080/
r.HandleFunc("GET /", func(_ http.ResponseWriter, _ *http.Request) {
panic("example recvery")
})
_ = http.ListenAndServe("[::]:8080", r.Compile())
}
Output:
Types ¶
type Option ¶
type Option func(*config)
Option configures recovery middleware.
func WithErrorHandler ¶
func WithErrorHandler(errorHandler func(w http.ResponseWriter, err any)) Option
WithErrorHandler sets the panic handler used by the middleware.
Click to show internal directories.
Click to hide internal directories.