Skip to content

🧹 chore: Add FullPath() helper to context#3837

Merged
ReneWerner87 merged 3 commits intomainfrom
implement-fullpath-helper-in-ctx.go
Nov 4, 2025
Merged

🧹 chore: Add FullPath() helper to context#3837
ReneWerner87 merged 3 commits intomainfrom
implement-fullpath-helper-in-ctx.go

Conversation

@gaby
Copy link
Member

@gaby gaby commented Nov 4, 2025

Summary

  • Similar to gin, add a FullPath() helper to Ctx that exposes the matched route path.

Fixes #3832

@gaby gaby requested a review from a team as a code owner November 4, 2025 04:48
@gaby gaby requested review from ReneWerner87, Copilot, efectn and sixcolors and removed request for Copilot November 4, 2025 04:48
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 4, 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.

Walkthrough

Added a new public accessor FullPath() string to the Ctx interface and implemented it on DefaultCtx. Tests and documentation were added to exercise and document returning the matched route path including group/mount prefixes.

Changes

Cohort / File(s) Description
Implementation
ctx.go, ctx_interface_gen.go
Added FullPath() string to the Ctx interface and implemented func (c *DefaultCtx) FullPath() string returning the matched route's Path (includes group/mount prefixes).
Tests
ctx_test.go
Added tests: Test_Ctx_FullPath, Test_Ctx_FullPath_Group, Test_Ctx_FullPath_Middleware validating FullPath() in root, grouped, and middleware flows.
Documentation
docs/api/ctx.md
Documented new FullPath() string accessor and added usage examples showing returned value (including behavior before/after Next()).
Manifest
go.mod
Module manifest present in diff context (no functional changes in manifest).

Sequence Diagram(s)

sequenceDiagram
    participant Req as HTTP Request
    participant Router as App Router
    participant Ctx as DefaultCtx
    participant Route as Route

    Note over Router,Route: incoming request matched to a Route (may include group prefix)
    Req ->> Router: HTTP request
    Router ->> Route: match route (including group/mount)
    Router ->> Ctx: create DefaultCtx (attach Route)
    Ctx ->> Route: access Route.Path
    Route -->> Ctx: "/v1/test"  %% example composed path
    Note right of Ctx: handlers/middleware can call FullPath()\nbefore and after Next()
    Ctx ->> Ctx: FullPath() returns matched route path
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review concurrency/lifecycle where Route is accessed from DefaultCtx (nil or unset Route cases).
  • Verify tests cover nested groups and middleware ordering edge cases.

Possibly related PRs

Suggested reviewers

  • sixcolors
  • ReneWerner87
  • efectn

Poem

🐰 I hopped through code with nimble paws,
FullPath now shows the route I saw.
Grouped or root, middleware too—
I fetch the path and share the view. 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive The PR description is minimal but references the linked issue #3832. However, it lacks detailed information on documentation updates, tests, and other template sections. Expand the description to include details about test additions, documentation updates in /docs/, and API compatibility with Express/Gin frameworks as specified in the template.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the main change: adding a FullPath() helper method to the context. It's concise and clearly conveys the purpose despite using the chore label.
Linked Issues check ✅ Passed The PR successfully implements the FullPath() method to return the matched route pattern including group prefixes, directly addressing issue #3832's request for Gin-like functionality.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the FullPath() helper: interface definition, implementation, tests, and documentation. No extraneous modifications were introduced.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch implement-fullpath-helper-in-ctx.go

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ec36bdd and e843b11.

📒 Files selected for processing (1)
  • docs/api/ctx.md (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/api/ctx.md
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: unit (1.25.x, windows-latest)
  • GitHub Check: unit (1.25.x, macos-13)
  • GitHub Check: unit (1.25.x, macos-latest)
  • GitHub Check: repeated
  • GitHub Check: Compare
  • GitHub Check: lint

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 significant enhancement by providing a FullPath helper within the Ctx object. This new method allows developers to easily access the complete, matched route path, including any prefixes from route groups. This improves the clarity and utility of route introspection within application handlers, making it simpler to understand and utilize the exact route that was matched for a given request.

Highlights

  • New FullPath Helper: A new FullPath() method has been added to the Ctx interface and its DefaultCtx implementation, allowing retrieval of the full matched route path, including any group prefixes.
  • Interface and Documentation Updates: The Ctx interface has been updated to include the new FullPath() method, and the API documentation (docs/api/ctx.md) now features a dedicated section with examples for its usage.
  • Comprehensive Testing: Unit tests have been added to cover the FullPath() helper for both standard routes and routes defined within groups, ensuring its correct behavior in various routing scenarios.
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 Add FullPath helper to context 🧹 chore: Add FullPath() helper to context Nov 4, 2025
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 FullPath helper to the context, which is a useful addition for getting the complete matched route path, including group prefixes. The implementation is straightforward and correct, and it's well-covered by tests and documentation. I have one suggestion to refactor the new tests for better maintainability.

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)
ctx_interface_gen.go (1)

113-114: Doc tweak for unmatched routes (optional)

Consider clarifying behavior when no route matched, e.g., “If no route matched, returns the original request path.” This mirrors the implementation suggestion in ctx.go.

- // FullPath returns the matched route path, including any group prefixes.
+ // FullPath returns the matched route path, including any group prefixes.
+ // If no route matched, returns the original request path.
ctx.go (2)

320-324: Avoid allocation when no route matched; clarify doc

Route() allocates a new Route when c.route is nil. Return directly from fields to avoid that and document the unmatched case.

-// FullPath returns the matched route path, including any group prefixes.
-func (c *DefaultCtx) FullPath() string {
-	return c.Route().Path
-}
+// FullPath returns the matched route path, including any group prefixes.
+// If no route matched, returns the original request path.
+func (c *DefaultCtx) FullPath() string {
+	if c.route != nil {
+		return c.route.Path
+	}
+	return c.pathOriginal
+}

320-324: Formatting/build hygiene

Please run the repo’s Go targets to satisfy project guidelines: gofumpt formatting, betteralign, and gopls modernize (e.g., make format betteralign modernize).

ctx_test.go (1)

3656-3690: Good coverage; add param/unmatched cases (optional)

Current tests validate static and grouped routes. Recommend adding:

  • Param route returns pattern: e.g., GET /users/:id → “/users/:id”.
  • Unmatched path returns original path (if adopting the doc/impl suggestion).

Example additions:

func Test_Ctx_FullPath_Params(t *testing.T) {
	t.Parallel()
	app := New()
	app.Get("/users/:id", func(c Ctx) error {
		require.Equal(t, "/users/:id", c.FullPath())
		return c.SendStatus(StatusOK)
	})
	resp, err := app.Test(httptest.NewRequest(MethodGet, "/users/42", nil))
	require.NoError(t, err)
	require.Equal(t, StatusOK, resp.StatusCode)
}

func Test_Ctx_FullPath_Unmatched(t *testing.T) {
	t.Parallel()
	app := New()
	// no routes
	resp, err := app.Test(httptest.NewRequest(MethodGet, "/missing", nil))
	require.NoError(t, err)
	require.Equal(t, StatusNotFound, resp.StatusCode)
	// Acquire to inspect FullPath() behavior on unmatched
	c := app.AcquireCtx(&fasthttp.RequestCtx{})
	defer app.ReleaseCtx(c)
	c.Request().SetRequestURI("/missing")
	require.Equal(t, "/missing", c.FullPath())
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0edd81d and d03cfa3.

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

📄 CodeRabbit inference engine (AGENTS.md)

**/*.go: Apply formatting using gofumpt (Make target: format)
Optimize struct field alignment using betteralign (Make target: betteralign)
Modernize code using gopls modernize (Make target: modernize)

Files:

  • ctx_interface_gen.go
  • ctx.go
  • ctx_test.go
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 (2)
📚 Learning: 2024-11-10T23:44:13.704Z
Learnt from: gaby
Repo: gofiber/fiber PR: 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:

  • ctx.go
  • docs/api/ctx.md
📚 Learning: 2024-11-08T04:10:42.990Z
Learnt from: gaby
Repo: gofiber/fiber PR: 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
🧬 Code graph analysis (2)
ctx.go (1)
router.go (1)
  • Route (43-64)
ctx_test.go (4)
app.go (1)
  • New (521-634)
ctx_interface_gen.go (1)
  • Ctx (18-428)
constants.go (2)
  • StatusOK (52-52)
  • MethodGet (5-5)
group.go (1)
  • Group (14-21)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: unit (1.25.x, macos-latest)
  • GitHub Check: unit (1.25.x, windows-latest)
  • GitHub Check: Compare
  • GitHub Check: repeated
  • GitHub Check: lint
🔇 Additional comments (2)
ctx_interface_gen.go (1)

113-114: Public interface addition: confirm breakage is acceptable and document it

Adding FullPath() to Ctx is a source-breaking change for any external types implementing Ctx without embedding DefaultCtx. Please confirm this is intended for v3 and ensure release notes/docs call it out. Also regenerate the interface via the existing go:generate flow so the generated file remains authoritative.

docs/api/ctx.md (1)

423-438: Documentation for FullPath() is well-structured and clear.

The new section is properly formatted, includes a clear description explaining that the method returns the full matched route path including group/mount prefixes, and provides a concrete example demonstrating this with a grouped route. The placement between Route and Matched sections is logical, and the documentation follows established patterns in the file.

@gaby
Copy link
Member Author

gaby commented Nov 4, 2025

Let me report the above to CodeRabbit

Copilot AI review requested due to automatic review settings November 4, 2025 05:35
@codecov
Copy link

codecov bot commented Nov 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.26%. Comparing base (0edd81d) to head (ec36bdd).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3837   +/-   ##
=======================================
  Coverage   92.26%   92.26%           
=======================================
  Files         115      115           
  Lines        9742     9744    +2     
=======================================
+ Hits         8988     8990    +2     
  Misses        480      480           
  Partials      274      274           
Flag Coverage Δ
unittests 92.26% <100.00%> (+<0.01%) ⬆️

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

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 adds a new FullPath() method to the Fiber context that returns the full matched route path including any group prefixes. This provides a convenient way to access the complete route pattern without needing to call Route().Path directly.

  • Adds FullPath() method to the Ctx interface and DefaultCtx implementation
  • Includes comprehensive test coverage for basic routes, grouped routes, and middleware behavior
  • Documents the new method with examples showing usage in routes and middleware

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
ctx.go Implements the FullPath() method that delegates to Route().Path
ctx_interface_gen.go Adds FullPath() to the Ctx interface definition
ctx_test.go Adds three test cases covering basic usage, grouped routes, and middleware scenarios
docs/api/ctx.md Documents the new method with signature, description, and usage examples

@ReneWerner87 ReneWerner87 added this to the v3 milestone Nov 4, 2025
@ReneWerner87 ReneWerner87 added this to v3 Nov 4, 2025
@ReneWerner87 ReneWerner87 merged commit bc74824 into main Nov 4, 2025
14 checks passed
@ReneWerner87 ReneWerner87 deleted the implement-fullpath-helper-in-ctx.go branch November 4, 2025 07:45
@github-project-automation github-project-automation bot moved this to Done in v3 Nov 4, 2025
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.

🤗 [Question]: How to implement the ctx. FullPath() method similar to the one in gin

3 participants