Skip to content

docs: clarify context interface implementation#3729

Merged
ReneWerner87 merged 2 commits intomainfrom
codex/2025-09-03-19-55-32
Sep 3, 2025
Merged

docs: clarify context interface implementation#3729
ReneWerner87 merged 2 commits intomainfrom
codex/2025-09-03-19-55-32

Conversation

@ReneWerner87
Copy link
Member

Summary

  • rename Context() section to Context
  • move context.Context description near the top to clarify the interface implementation

Testing

  • make audit (fails: EncodeMsg/MarshalMsg/Msgsize passes lock by value in msgp-generated files)
  • make generate
  • make betteralign
  • make modernize
  • make format
  • make test (fails: Test_App_BodyLimit_Zero: i/o timeout)

https://chatgpt.com/codex/tasks/task_e_68b87e5f72288326a3f76384c208d3c0

Copilot AI review requested due to automatic review settings September 3, 2025 19:55
@ReneWerner87 ReneWerner87 requested a review from a team as a code owner September 3, 2025 19:55
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 3, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a new top-level context.Context section to docs/api/ctx.md documenting that fiber.Ctx implements context.Context, lists Deadline/Done/Err/Value signatures, provides examples (including Value and App()), notes fasthttp limitations and Ctx reuse, removes the old Context() section, and updates the SetContext anchor.

Changes

Cohort / File(s) Summary
Docs: context.Context restructuring
docs/api/ctx.md
Replaced the old Context() section with a new top-level context.Context section: added method signatures (Deadline, Done, Err, Value), examples (including Value and App()), notes about fasthttp no-ops and Ctx reuse, and updated the SetContext anchor to reference the new section.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Client
  participant Fiber as Fiber Router
  participant Handler as Route Handler
  participant Func as Function(ctx.Context)

  Client->>Fiber: HTTP Request
  Fiber->>Handler: Invoke(c fiber.Ctx)
  note right of Handler #F8F0E6: c implements context.Context\n(Deadline/Done/Err are no-ops per fasthttp)
  Handler->>Func: Call with c (as context.Context)
  Func-->>Handler: Result / error
  Handler-->>Fiber: Response
  Fiber-->>Client: HTTP Response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested reviewers

  • gaby
  • sixcolors
  • efectn

Poem

Little paws tap on the doc-lined trail,
I hop through Context, leaving a soft tail.
Values tucked in cozy Locals' nest,
Deadlines nap while Done takes rest.
I bound away — docs polished and hale. 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between ff712ea and 83d2935.

📒 Files selected for processing (1)
  • docs/api/ctx.md (2 hunks)
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/2025-09-03-19-55-32

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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.

Summary of Changes

Hello @ReneWerner87, 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 primarily focuses on improving the clarity and organization of the fiber.Ctx documentation, specifically regarding its interaction with Go's context.Context interface. The changes aim to make it easier for users to understand how fiber.Ctx implements context.Context and how to correctly obtain a usable context.Context instance.

Highlights

  • Documentation Structure: The context.Context implementation details for fiber.Ctx have been moved to a more prominent position at the top of the docs/api/ctx.md file.
  • Section Renaming: The documentation section previously titled Context() has been renamed to Context for consistency and clarity.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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.

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 clarifies the context interface implementation in the Fiber documentation by reorganizing and improving the documentation structure for context-related methods.

  • Moves the context.Context interface implementation description to the top of the document for better visibility
  • Renames the Context() section to Context for consistency
  • Updates internal cross-references to match the new section naming

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 refactors the documentation for Ctx to improve clarity around its implementation of context.Context. The changes primarily involve moving the detailed explanation to a new context.Context section and renaming the Context() section to Context. These changes make the documentation more logical and easier to follow. I've added a couple of minor suggestions to further improve consistency and readability.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (4)
docs/api/ctx.md (4)

13-13: Polish phrasing: “no-op(s)” and sentence flow

Suggest tightening wording and using the conventional “no-op(s)”.

-`Ctx` implements `context.Context`. However due to [current limitations in how fasthttp](https://github.com/valyala/fasthttp/issues/965#issuecomment-777268945) works, `Deadline()`, `Done()` and `Err()` operate as a nop. The `fiber.Ctx` instance is reused after the handler returns and must not be used for asynchronous operations once the handler has completed. Call [`Context`](#context) within the handler to obtain a `context.Context` that can be used outside the handler.
+`Ctx` implements `context.Context`. However, due to [current fasthttp limitations](https://github.com/valyala/fasthttp/issues/965#issuecomment-777268945), `Deadline()`, `Done()`, and `Err()` are no-ops. The `fiber.Ctx` instance is reused after the handler returns and must not be used for asynchronous operations once the handler has completed. Call [`Context`](#context) within the handler to obtain a `context.Context` that can be used outside the handler.

22-31: Add an async-safe example using c.Context()

The text advises using Context() for work outside the handler; add a short companion example to demonstrate it.

 ```go title="Example"
 func doSomething(ctx context.Context) {
   // ...
 }
 
 app.Get("/", func(c fiber.Ctx) error {
   doSomething(c)
+  // For asynchronous work, derive a context that is safe after the handler returns:
+  ctx := c.Context()
+  go doAsyncWork(ctx)
+  return nil
 })

---

`37-41`: **Show type assertion when using Value**

`Value` returns `any`; demonstrating a type assertion improves correctness and mirrors the `Locals` example below.



```diff
 app.Get("/", func(c fiber.Ctx) error {
   c.Locals(userKey, "admin")
-  user := c.Value(userKey) // returns "admin"
+  user, _ := c.Value(userKey).(string) // "admin"
+  _ = user
 })

96-96: Fix spelling: “cancellation”

Minor spelling issue.

-Sets the base `context.Context` used by [`Context`](#context). Use this to
-propagate deadlines, cancelation signals, or values to asynchronous operations.
+Sets the base `context.Context` used by [`Context`](#context). Use this to
+propagate deadlines, cancellation signals, or values to asynchronous operations.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f1b7f6d and ff712ea.

📒 Files selected for processing (1)
  • docs/api/ctx.md (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
docs/**

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Review and update the contents of the docs folder if necessary when modifying code

Files:

  • docs/api/ctx.md
🧠 Learnings (3)
📓 Common learnings
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, `Context()` is being renamed to `RequestCtx()`, and `UserContext()` to `Context()` to improve clarity and align with Go's context conventions.
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the `middleware/adaptor/adaptor.go` file of the Fiber framework, when updating context handling, replacing `c.Context()` with `c.RequestCtx()` is appropriate to access the `fasthttp.RequestCtx`.
📚 Learning: 2024-11-08T04:10:42.990Z
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/cache/cache_test.go:897-897
Timestamp: 2024-11-08T04:10:42.990Z
Learning: In the Fiber framework, `Context()` is being renamed to `RequestCtx()`, and `UserContext()` to `Context()` to improve clarity and align with Go's context conventions.

Applied to files:

  • docs/api/ctx.md
📚 Learning: 2024-11-10T23:44:13.704Z
Learnt from: gaby
PR: gofiber/fiber#3193
File: middleware/adaptor/adaptor.go:111-111
Timestamp: 2024-11-10T23:44:13.704Z
Learning: In the `middleware/adaptor/adaptor.go` file of the Fiber framework, when updating context handling, replacing `c.Context()` with `c.RequestCtx()` is appropriate to access the `fasthttp.RequestCtx`.

Applied to files:

  • docs/api/ctx.md
🪛 LanguageTool
docs/api/ctx.md

[grammar] ~13-~13: There might be a mistake here.
Context: ...e handler to obtain a context.Context that can be used outside the handler. ```go...

(QB_NEW_EN)


[grammar] ~96-~96: There might be a mistake here.
Context: ...ed by Context. Use this to propagate deadlines, cancelation signals...

(QB_NEW_EN)

@ReneWerner87 ReneWerner87 enabled auto-merge (squash) September 3, 2025 20:52
@ReneWerner87 ReneWerner87 enabled auto-merge (squash) September 3, 2025 20:52
@ReneWerner87 ReneWerner87 added this to the v3 milestone Sep 3, 2025
@ReneWerner87 ReneWerner87 added this to v3 Sep 3, 2025
@ReneWerner87 ReneWerner87 added the v3 label Sep 3, 2025
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@ReneWerner87 ReneWerner87 merged commit c26277f into main Sep 3, 2025
1 of 2 checks passed
@ReneWerner87 ReneWerner87 deleted the codex/2025-09-03-19-55-32 branch September 3, 2025 20:55
@github-project-automation github-project-automation bot moved this to Done in v3 Sep 3, 2025
Abhirup-99 pushed a commit to Abhirup-99/fiber that referenced this pull request Nov 3, 2025
* docs: clarify context implementation

* Update docs/api/ctx.md

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants