From 878f3eca81a5d2b39ec1e84b09282ce111e36b5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Gro=C3=9Fe?= Date: Mon, 13 Mar 2023 13:19:35 +0000 Subject: [PATCH] requestid.Config.ContextKey is interface{} Consistent with c.Locals(key inteface{}, ...). Fixes #2356 --- docs/api/middleware/requestid.md | 2 +- middleware/requestid/config.go | 2 +- middleware/requestid/requestid_test.go | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/docs/api/middleware/requestid.md b/docs/api/middleware/requestid.md index 9db86af7b1..7617f76ae9 100644 --- a/docs/api/middleware/requestid.md +++ b/docs/api/middleware/requestid.md @@ -61,7 +61,7 @@ type Config struct { // the locals for a specific request. // // Optional. Default: requestid - ContextKey string + ContextKey interface{} } ``` diff --git a/middleware/requestid/config.go b/middleware/requestid/config.go index b3b605e590..cc69907822 100644 --- a/middleware/requestid/config.go +++ b/middleware/requestid/config.go @@ -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 diff --git a/middleware/requestid/requestid_test.go b/middleware/requestid/requestid_test.go index 451e96b4b2..ee3d33d629 100644 --- a/middleware/requestid/requestid_test.go +++ b/middleware/requestid/requestid_test.go @@ -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() })