Skip to content

Commit c291eba

Browse files
committed
requestid.Config.ContextKey is interface{}
Consistent with c.Locals(key inteface{}, ...). Fixes #2356
1 parent 634f163 commit c291eba

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

Diff for: docs/api/middleware/requestid.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ type Config struct {
6161
// the locals for a specific request.
6262
//
6363
// Optional. Default: requestid
64-
ContextKey string
64+
ContextKey interface{}
6565
}
6666
```
6767

Diff for: middleware/requestid/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type Config struct {
2626
// the locals for a specific request.
2727
//
2828
// Optional. Default: requestid
29-
ContextKey string
29+
ContextKey interface{}
3030
}
3131

3232
// ConfigDefault is the default config

Diff for: middleware/requestid/requestid_test.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -55,20 +55,21 @@ func Test_RequestID_Next(t *testing.T) {
5555
func Test_RequestID_Locals(t *testing.T) {
5656
t.Parallel()
5757
reqID := "ThisIsARequestId"
58-
ctxKey := "ThisIsAContextKey"
58+
type ContextKey int
59+
const RequestContextKey = iota
5960

6061
app := fiber.New()
6162
app.Use(New(Config{
6263
Generator: func() string {
6364
return reqID
6465
},
65-
ContextKey: ctxKey,
66+
ContextKey: RequestContextKey,
6667
}))
6768

6869
var ctxVal string
6970

7071
app.Use(func(c *fiber.Ctx) error {
71-
ctxVal = c.Locals(ctxKey).(string) //nolint:forcetypeassert,errcheck // We always store a string in here
72+
ctxVal = c.Locals(RequestContextKey).(string) //nolint:forcetypeassert,errcheck // We always store a string in here
7273
return c.Next()
7374
})
7475

0 commit comments

Comments
 (0)