gofiber-recovery-middleware is a gofiber middleware intended to recover and log panics.
go get github.com/rgglez/gofiber-recovery-middlewareimport gofiberrecovery "github.com/rgglez/gofiber-recovery-middleware/gofiberrecovery"
// Initialize Fiber app and middleware
app := fiber.New()
app.Use(gofiberrecovery.New(gofiberrecovery.Config{/* your configuration here */}))There are some configuration options available in the Config struct:
Nextdefines a function to skip this middleware when it returns true.Loggerit is the zerolog instance to record panics.TimeKeyFuncfunction to generate the time_key in the logs.SkipFramesnumber of frames to skip in the stack trace (default: 4).EnableStackTraceenables full stack trace logging.CustomResponseallows you to customize the HTTP response in case of panic.OnPanicadditional callback that executes when a panic occurs.
An example is included in the example directory. To execute it:
-
Enter the example directory.
-
Run the example:
go run . -
In your browser open
Copyright (c) 2025 Rodolfo González González.
Licensed under the Apache 2.0 license. Read the LICENSE file.