mirror of https://github.com/gofiber/fiber.git
This reverts commit d7b36cde
pull/2744/head
parent
6b9630b5f7
commit
28be17f929
|
@ -45,7 +45,7 @@ app.Use(requestid.New(requestid.Config{
|
||||||
| Next | `func(*fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` |
|
| Next | `func(*fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` |
|
||||||
| Header | `string` | Header is the header key where to get/set the unique request ID. | "X-Request-ID" |
|
| Header | `string` | Header is the header key where to get/set the unique request ID. | "X-Request-ID" |
|
||||||
| Generator | `func() string` | Generator defines a function to generate the unique identifier. | utils.UUID |
|
| Generator | `func() string` | Generator defines a function to generate the unique identifier. | utils.UUID |
|
||||||
| ContextKey | `interface{}` | ContextKey defines the key used when storing the request ID in the locals for a specific request. | "requestid" |
|
| ContextKey | `string` | ContextKey defines the key used when storing the request ID in the locals for a specific request. | "requestid" |
|
||||||
|
|
||||||
## Default Config
|
## Default Config
|
||||||
The default config uses a fast UUID generator which will expose the number of
|
The default config uses a fast UUID generator which will expose the number of
|
||||||
|
|
|
@ -26,7 +26,7 @@ type Config struct {
|
||||||
// the locals for a specific request.
|
// the locals for a specific request.
|
||||||
//
|
//
|
||||||
// Optional. Default: requestid
|
// Optional. Default: requestid
|
||||||
ContextKey interface{}
|
ContextKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConfigDefault is the default config
|
// ConfigDefault is the default config
|
||||||
|
|
|
@ -55,21 +55,20 @@ func Test_RequestID_Next(t *testing.T) {
|
||||||
func Test_RequestID_Locals(t *testing.T) {
|
func Test_RequestID_Locals(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
reqID := "ThisIsARequestId"
|
reqID := "ThisIsARequestId"
|
||||||
type ContextKey int
|
ctxKey := "ThisIsAContextKey"
|
||||||
const requestContextKey ContextKey = iota
|
|
||||||
|
|
||||||
app := fiber.New()
|
app := fiber.New()
|
||||||
app.Use(New(Config{
|
app.Use(New(Config{
|
||||||
Generator: func() string {
|
Generator: func() string {
|
||||||
return reqID
|
return reqID
|
||||||
},
|
},
|
||||||
ContextKey: requestContextKey,
|
ContextKey: ctxKey,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
var ctxVal string
|
var ctxVal string
|
||||||
|
|
||||||
app.Use(func(c *fiber.Ctx) error {
|
app.Use(func(c *fiber.Ctx) error {
|
||||||
ctxVal = c.Locals(requestContextKey).(string) //nolint:forcetypeassert,errcheck // We always store a string in here
|
ctxVal = c.Locals(ctxKey).(string) //nolint:forcetypeassert,errcheck // We always store a string in here
|
||||||
return c.Next()
|
return c.Next()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue