🐛 requestid.Config.ContextKey is interface{} (#2369)

requestid.Config.ContextKey is interface{}

Consistent with c.Locals(key inteface{}, ...).
Fixes #2356
pull/2371/head
Benjamin Grosse 2023-03-14 18:37:10 +00:00 committed by GitHub
parent 678728de6d
commit d7b36cde54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View File

@ -61,7 +61,7 @@ type Config struct {
// the locals for a specific request. // the locals for a specific request.
// //
// Optional. Default: requestid // Optional. Default: requestid
ContextKey string ContextKey interface{}
} }
``` ```

View File

@ -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 string ContextKey interface{}
} }
// ConfigDefault is the default config // ConfigDefault is the default config

View File

@ -55,20 +55,21 @@ 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"
ctxKey := "ThisIsAContextKey" type ContextKey int
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: ctxKey, ContextKey: requestContextKey,
})) }))
var ctxVal string var ctxVal string
app.Use(func(c *fiber.Ctx) error { 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() return c.Next()
}) })