title | keywords | description | ||
---|---|---|---|---|
Recover Middleware |
|
Recover middleware for error handling. |
This project demonstrates how to implement a recovery mechanism in a Go application using the Fiber framework's Recover
middleware.
Ensure you have the following installed:
- Golang
- Fiber package
-
Clone the repository:
git clone https://github.com/gofiber/recipes.git cd recipes/recover
-
Install dependencies:
go get
- Start the application:
go run main.go
Here is an example of how to set up the Recover
middleware in a Fiber application:
package main
import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/recover"
)
func main() {
app := fiber.New()
// Use the Recover middleware
app.Use(recover.New())
app.Get("/", func(c *fiber.Ctx) error {
// This will cause a panic
panic("something went wrong")
})
app.Listen(":3000")
}