Skip to content

Commit

Permalink
🐛 requestid.Config.ContextKey is interface{} (#2369)
Browse files Browse the repository at this point in the history
requestid.Config.ContextKey is interface{}

Consistent with c.Locals(key inteface{}, ...).
Fixes #2356
  • Loading branch information
benjajaja committed Mar 14, 2023
1 parent 678728d commit d7b36cd
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/api/middleware/requestid.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type Config struct {
// the locals for a specific request.
//
// Optional. Default: requestid
ContextKey string
ContextKey interface{}
}
```

Expand Down
2 changes: 1 addition & 1 deletion middleware/requestid/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions middleware/requestid/requestid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})

Expand Down

0 comments on commit d7b36cd

Please sign in to comment.