Skip to content

Commit

Permalink
Revert ":bug: requestid.Config.ContextKey is interface{} (#2369)" (#2742
Browse files Browse the repository at this point in the history
)

This reverts commit d7b36cd
  • Loading branch information
ReneWerner87 authored Nov 27, 2023
1 parent 6b9630b commit 28be17f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/api/middleware/requestid.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ app.Use(requestid.New(requestid.Config{
| Next | `func(*fiber.Ctx) bool` | Next defines a function to skip this middleware when returned true. | `nil` |
| Header | `string` | Header is the header key where to get/set the unique request ID. | "X-Request-ID" |
| Generator | `func() string` | Generator defines a function to generate the unique identifier. | utils.UUID |
| ContextKey | `interface{}` | ContextKey defines the key used when storing the request ID in the locals for a specific request. | "requestid" |
| ContextKey | `string` | ContextKey defines the key used when storing the request ID in the locals for a specific request. | "requestid" |

## Default Config
The default config uses a fast UUID generator which will expose the number of
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 interface{}
ContextKey string
}

// ConfigDefault is the default config
Expand Down
7 changes: 3 additions & 4 deletions middleware/requestid/requestid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,20 @@ func Test_RequestID_Next(t *testing.T) {
func Test_RequestID_Locals(t *testing.T) {
t.Parallel()
reqID := "ThisIsARequestId"
type ContextKey int
const requestContextKey ContextKey = iota
ctxKey := "ThisIsAContextKey"

app := fiber.New()
app.Use(New(Config{
Generator: func() string {
return reqID
},
ContextKey: requestContextKey,
ContextKey: ctxKey,
}))

var ctxVal string

app.Use(func(c *fiber.Ctx) error {
ctxVal = c.Locals(requestContextKey).(string) //nolint:forcetypeassert,errcheck // We always store a string in here
ctxVal = c.Locals(ctxKey).(string) //nolint:forcetypeassert,errcheck // We always store a string in here
return c.Next()
})

Expand Down

0 comments on commit 28be17f

Please sign in to comment.