Skip to content

🧹 chore: Improve context helpers#4093

Merged
ReneWerner87 merged 4 commits intoupdate-middleware-helpers-for-context-typesfrom
add-helper-for-locals-and-context-storage
Feb 23, 2026
Merged

🧹 chore: Improve context helpers#4093
ReneWerner87 merged 4 commits intoupdate-middleware-helpers-for-context-typesfrom
add-helper-for-locals-and-context-storage

Conversation

@gaby
Copy link
Member

@gaby gaby commented Feb 19, 2026

This pull request introduces a new StoreInContext helper function designed to streamline how request-scoped values are stored and retrieved within Fiber applications. This helper ensures that values are consistently accessible via both c.Locals() and the underlying context.Context, simplifying middleware development and promoting a more unified approach to context management across the framework. Existing middlewares have been refactored to adopt this new utility.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 19, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

🗂️ Base branches to auto review (3)
  • master
  • v2
  • main

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-helper-for-locals-and-context-storage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @gaby, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new StoreInContext helper function designed to streamline how request-scoped values are stored and retrieved within Fiber applications. This helper ensures that values are consistently accessible via both c.Locals() and the underlying context.Context, simplifying middleware development and promoting a more unified approach to context management across the framework. Existing middlewares have been refactored to adopt this new utility.

Highlights

  • New StoreInContext Helper: Introduced a new fiber.StoreInContext function to consistently store values in both fiber.Ctx.Locals() and the context.Context, ensuring unified access.
  • Middleware Refactoring: Several core middlewares (BasicAuth, CSRF, KeyAuth, RequestID, Session) were updated to utilize the new StoreInContext helper, reducing boilerplate and improving maintainability by centralizing value storage.
  • Documentation Updates: The official guide and "What's New" documentation were updated to reflect the introduction and proper usage of the StoreInContext helper.
  • ValueFromContext Adjustment: The ValueFromContext helper was modified to retrieve values specifically from c.Locals() for fiber.Ctx types, aligning with the new standardized storage mechanism.
  • Test Coverage: A new test case was added for StoreInContext to ensure its correct functionality and consistent behavior.
Changelog
  • docs/guide/context.md
    • Added guidance on using fiber.StoreInContext for managing request-scoped values.
  • docs/whats_new.md
    • Documented the new StoreInContext generic function in the 'New Generic Functions' section.
  • helpers.go
    • Modified ValueFromContext to retrieve values from c.Locals() for fiber.Ctx.
    • Introduced the StoreInContext function to store key/value pairs in both Fiber locals and the request context.
  • helpers_test.go
    • Added TestStoreInContext to verify the functionality of the new helper function.
  • middleware/basicauth/basicauth.go
    • Removed the direct context import.
    • Refactored to use fiber.StoreInContext for storing authenticated usernames.
  • middleware/csrf/csrf.go
    • Removed the direct context import.
    • Refactored to use fiber.StoreInContext for storing CSRF handlers and tokens.
  • middleware/keyauth/keyauth.go
    • Removed the direct context import.
    • Refactored to use fiber.StoreInContext for storing API keys.
  • middleware/requestid/requestid.go
    • Removed the direct context import.
    • Refactored to use fiber.StoreInContext for storing request IDs.
  • middleware/session/middleware.go
    • Removed the direct context import.
    • Refactored to use fiber.StoreInContext for storing session middleware context.
Activity
  • The pull request was automatically generated by Codex.
  • The initial generation encountered an unexpected error, resulting in a placeholder message.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gaby gaby changed the title Codex-generated pull request 🧹 chore: Improve context helpers Feb 19, 2026
@gaby gaby requested a review from Copilot February 19, 2026 14:31
@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.99%. Comparing base (2929278) to head (719a67b).

Additional details and impacted files
@@                               Coverage Diff                               @@
##           update-middleware-helpers-for-context-types    #4093      +/-   ##
===============================================================================
- Coverage                                        91.07%   90.99%   -0.08%     
===============================================================================
  Files                                              119      119              
  Lines                                            11335    11333       -2     
===============================================================================
- Hits                                             10323    10313      -10     
- Misses                                             642      648       +6     
- Partials                                           370      372       +2     
Flag Coverage Δ
unittests 90.99% <100.00%> (-0.08%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new helper function fiber.StoreInContext to simplify storing request-scoped values in both c.Locals() and the request's context.Context. This is a great addition for consistency and reducing code duplication. The existing middleware (basicauth, csrf, keyauth, requestid, session) has been refactored to use this new helper, which makes the code cleaner and more maintainable. The changes also include updates to documentation and a new test for the helper function, which are well-written. The small adjustment in ValueFromContext to use Locals instead of Value for fiber.Ctx is also a good idiomatic improvement. Overall, this is a solid pull request with no issues found.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a new StoreInContext helper function that consolidates the pattern of storing values in both c.Locals() and c.Context() simultaneously. This refactoring improves code maintainability by eliminating duplication across multiple middlewares while ensuring request-scoped values remain accessible via both APIs.

Changes:

  • Added fiber.StoreInContext helper function to store values in both Fiber locals and the request context
  • Modified ValueFromContext to use Locals() instead of Value() for fiber.Ctx types (functionally equivalent, as both use fasthttp.UserValue internally)
  • Refactored five middlewares (session, requestid, keyauth, csrf, basicauth) to use the new helper
  • Added comprehensive test coverage for StoreInContext
  • Updated documentation in whats_new.md and context.md

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
helpers.go Added StoreInContext helper and updated ValueFromContext to use Locals() for fiber.Ctx
helpers_test.go Added test coverage for StoreInContext verifying values are stored in both locals and context
middleware/session/middleware.go Refactored to use fiber.StoreInContext, removed context import
middleware/requestid/requestid.go Refactored to use fiber.StoreInContext, removed context import
middleware/keyauth/keyauth.go Refactored to use fiber.StoreInContext, removed context import
middleware/csrf/csrf.go Refactored to use fiber.StoreInContext for both token and handler storage, removed context import
middleware/basicauth/basicauth.go Refactored to use fiber.StoreInContext, removed context import
docs/whats_new.md Documented the new StoreInContext helper function
docs/guide/context.md Added guidance on using StoreInContext for request-scoped values

@gaby gaby marked this pull request as ready for review February 22, 2026 19:47
@gaby gaby requested a review from a team as a code owner February 22, 2026 19:47
@gaby gaby requested review from ReneWerner87, Copilot, efectn and sixcolors and removed request for a team February 22, 2026 19:47
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 17 out of 17 changed files in this pull request and generated 3 comments.

@ReneWerner87 ReneWerner87 merged commit 05d6ba8 into update-middleware-helpers-for-context-types Feb 23, 2026
21 checks passed
@ReneWerner87 ReneWerner87 deleted the add-helper-for-locals-and-context-storage branch February 23, 2026 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants