Request ID
Request ID adds an identifier to the request using the X-Request-ID
header
Installation
- go get -u github.com/gofiber/requestid
Signature
- requestid.New(config ...Config) func(*Ctx)
Config
Property | Type | Description | Default |
---|---|---|---|
Filter | func(fiber.Ctx) bool | Defines a function to skip middleware | nil |
Generator | func(fiber.Ctx) string | Generator defines a function to generate an ID. | return uuid.New().String() |
Example
- package main
- import (
- "github.com/gofiber/fiber"
- "github.com/gofiber/requestid"
- )
- func main() {
- app := fiber.New()
- app.Use(requestid.New())
- app.Get("/", func(c *fiber.Ctx) {
- c.Send(requestid.Get(c))
- })
- app.Listen(3000)
- }