Skip to content

Latest commit

 

History

History
70 lines (49 loc) · 1.63 KB

README.md

File metadata and controls

70 lines (49 loc) · 1.63 KB
title keywords description
Recover Middleware
recover
middleware
Recover middleware for error handling.

Recover Middleware Example

Github StackBlitz

This project demonstrates how to implement a recovery mechanism in a Go application using the Fiber framework's Recover middleware.

Prerequisites

Ensure you have the following installed:

Setup

  1. Clone the repository:

    git clone https://github.com/gofiber/recipes.git
    cd recipes/recover
  2. Install dependencies:

    go get

Running the Application

  1. Start the application:
    go run main.go

Example

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")
}

References