Skip to content

rgglez/gofiber-recovery-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gofiber-recovery-middleware

License GitHub all releases GitHub issues GitHub commit activity Go Report Card GitHub release GitHub stars GitHub forks

gofiber-recovery-middleware is a gofiber middleware intended to recover and log panics.

Installation

go get github.com/rgglez/gofiber-recovery-middleware

Usage

import 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 */}))

Configuration

There are some configuration options available in the Config struct:

  • Next defines a function to skip this middleware when it returns true.
  • Logger it is the zerolog instance to record panics.
  • TimeKeyFunc function to generate the time_key in the logs.
  • SkipFrames number of frames to skip in the stack trace (default: 4).
  • EnableStackTrace enables full stack trace logging.
  • CustomResponse allows you to customize the HTTP response in case of panic.
  • OnPanic additional callback that executes when a panic occurs.

Example

An example is included in the example directory. To execute it:

  1. Enter the example directory.

  2. Run the example:

    go run .
  3. In your browser open

    http://127.0.0.1:3000/test-panic

Dependencies

License

Copyright (c) 2025 Rodolfo González González.

Licensed under the Apache 2.0 license. Read the LICENSE file.

About

Middleware to recover a panic in a gofiber application, and log information about it.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages