Request ID

Request ID adds an identifier to the request using the X-Request-ID header

Installation

  1. go get -u github.com/gofiber/requestid

Signature

  1. requestid.New(config ...Config) func(*Ctx)

Config

PropertyTypeDescriptionDefault
Filterfunc(fiber.Ctx) boolDefines a function to skip middlewarenil
Generatorfunc(fiber.Ctx) stringGenerator defines a function to generate an ID.return uuid.New().String()

Example

  1. package main
  2.  
  3. import (
  4. "github.com/gofiber/fiber"
  5. "github.com/gofiber/requestid"
  6. )
  7.  
  8. func main() {
  9. app := fiber.New()
  10.  
  11. app.Use(requestid.New())
  12.  
  13. app.Get("/", func(c *fiber.Ctx) {
  14. c.Send(requestid.Get(c))
  15. })
  16.  
  17. app.Listen(3000)
  18. }