Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't constrain middlewares' context-keys to strings 🐛 #2751

Merged
merged 3 commits into from
Dec 12, 2023

Commits on Dec 2, 2023

  1. Configuration menu
    Copy the full SHA
    2d41191 View commit details
    Browse the repository at this point in the history
  2. fix: request ContextKey default value condition

    Should check for `nil` since it is `any`.
    benjajaja committed Dec 2, 2023
    Configuration menu
    Copy the full SHA
    12c311c View commit details
    Browse the repository at this point in the history

Commits on Dec 9, 2023

  1. fix: don't constrain middlewares' context-keys to strings

    `context` recommends using "unexported type" as context keys to avoid
    collisions https://pkg.go.dev/github.com/gofiber/fiber/v2#Ctx.Locals.
    
    The official go blog also recommends this https://go.dev/blog/context.
    
    `fiber.Ctx.Locals(key any, value any)` correctly allows consumers to
    use unexported types or e.g. strings.
    
    But some fiber middlewares constrain their context-keys to `string` in
    their "default config structs", making it impossible to use unexported
    types.
    
    This PR removes the `string` _constraint_ from all middlewares, allowing
    to now use unexported types as per the official guidelines. However
    the default value is still a string, so it's not a breaking change, and
    anyone still using strings as context keys is not affected.
    benjajaja committed Dec 9, 2023
    Configuration menu
    Copy the full SHA
    c7359e7 View commit details
    Browse the repository at this point in the history