mirror of https://github.com/gofiber/fiber.git
🐛 requestid.Config.ContextKey is interface{} (#2369)
requestid.Config.ContextKey is interface{} Consistent with c.Locals(key inteface{}, ...). Fixes #2356pull/2371/head
parent
678728de6d
commit
d7b36cde54
|
@ -61,7 +61,7 @@ type Config struct {
|
|||
// the locals for a specific request.
|
||||
//
|
||||
// Optional. Default: requestid
|
||||
ContextKey string
|
||||
ContextKey interface{}
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ type Config struct {
|
|||
// the locals for a specific request.
|
||||
//
|
||||
// Optional. Default: requestid
|
||||
ContextKey string
|
||||
ContextKey interface{}
|
||||
}
|
||||
|
||||
// ConfigDefault is the default config
|
||||
|
|
|
@ -55,20 +55,21 @@ func Test_RequestID_Next(t *testing.T) {
|
|||
func Test_RequestID_Locals(t *testing.T) {
|
||||
t.Parallel()
|
||||
reqID := "ThisIsARequestId"
|
||||
ctxKey := "ThisIsAContextKey"
|
||||
type ContextKey int
|
||||
const requestContextKey ContextKey = iota
|
||||
|
||||
app := fiber.New()
|
||||
app.Use(New(Config{
|
||||
Generator: func() string {
|
||||
return reqID
|
||||
},
|
||||
ContextKey: ctxKey,
|
||||
ContextKey: requestContextKey,
|
||||
}))
|
||||
|
||||
var ctxVal string
|
||||
|
||||
app.Use(func(c *fiber.Ctx) error {
|
||||
ctxVal = c.Locals(ctxKey).(string) //nolint:forcetypeassert,errcheck // We always store a string in here
|
||||
ctxVal = c.Locals(requestContextKey).(string) //nolint:forcetypeassert,errcheck // We always store a string in here
|
||||
return c.Next()
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue