github.com/gofiber/fiber/v2@v2.47.0/docs/api/middleware/requestid.md (about) 1 --- 2 id: requestid 3 title: RequestID 4 --- 5 6 RequestID middleware for [Fiber](https://github.com/gofiber/fiber) that adds an indentifier to the response. 7 8 ## Signatures 9 10 ```go 11 func New(config ...Config) fiber.Handler 12 ``` 13 14 ## Examples 15 16 Import the middleware package that is part of the Fiber web framework 17 18 ```go 19 import ( 20 "github.com/gofiber/fiber/v2" 21 "github.com/gofiber/fiber/v2/middleware/requestid" 22 ) 23 ``` 24 25 After you initiate your Fiber app, you can use the following possibilities: 26 27 ```go 28 // Initialize default config 29 app.Use(requestid.New()) 30 31 // Or extend your config for customization 32 app.Use(requestid.New(requestid.Config{ 33 Header: "X-Custom-Header", 34 Generator: func() string { 35 return "static-id" 36 }, 37 })) 38 ``` 39 40 ## Config 41 42 ```go 43 // Config defines the config for middleware. 44 type Config struct { 45 // Next defines a function to skip this middleware when returned true. 46 // 47 // Optional. Default: nil 48 Next func(c *fiber.Ctx) bool 49 50 // Header is the header key where to get/set the unique request ID 51 // 52 // Optional. Default: "X-Request-ID" 53 Header string 54 55 // Generator defines a function to generate the unique identifier. 56 // 57 // Optional. Default: utils.UUID 58 Generator func() string 59 60 // ContextKey defines the key used when storing the request ID in 61 // the locals for a specific request. 62 // 63 // Optional. Default: requestid 64 ContextKey interface{} 65 } 66 ``` 67 68 ## Default Config 69 The default config uses a fast UUID generator which will expose the number of 70 requests made to the server. To conceal this value for better privacy, use the 71 `utils.UUIDv4` generator. 72 73 ```go 74 var ConfigDefault = Config{ 75 Next: nil, 76 Header: fiber.HeaderXRequestID, 77 Generator: utils.UUID, 78 ContextKey: "requestid", 79 } 80 ```