Skip to content

Conversation

@ReneWerner87
Copy link
Member

Adoption of the better logic for building the routing tree from the v2 bug fix #3454

@ReneWerner87 ReneWerner87 added this to the v3 milestone May 15, 2025
@ReneWerner87 ReneWerner87 requested a review from a team as a code owner May 15, 2025 14:18
@ReneWerner87 ReneWerner87 requested review from efectn, gaby and sixcolors May 15, 2025 14:18
@ReneWerner87 ReneWerner87 added this to v3 May 15, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 15, 2025

Walkthrough

This change removes route position and route count tracking logic from the application, router, and mount logic. It also updates related tests to eliminate assertions on these fields. Additionally, a new test is added to verify static middleware mounting alongside other routes and sub-applications.

Changes

File(s) Change Summary
app.go Removed the routesCount field from the App struct.
router.go Removed the pos field from Route, all related logic, and simplified route addition and tree-building methods.
mount.go Eliminated routePos tracking and atomic adjustments of routesCount during mounting.
mount_test.go Removed assertions related to routesCount and route position order in several mounting tests.
middleware/static/static_test.go Added a new test Test_Router_Mount_n_Static to verify static middleware mounting with other routes and sub-applications.

Sequence Diagram(s)

sequenceDiagram
    participant Test
    participant FiberApp
    participant StaticMiddleware
    participant SubApp

    Test->>FiberApp: Initialize app with static, root, and mount routes
    FiberApp->>StaticMiddleware: Mount static under /static
    FiberApp->>SubApp: Mount sub-app under /mount
    Test->>FiberApp: Send GET /static/style.css
    FiberApp->>StaticMiddleware: Serve static file
    StaticMiddleware-->>FiberApp: Return file response
    FiberApp-->>Test: Respond with status 200
Loading

Possibly related PRs

  • gofiber/fiber#3006: Introduces the static middleware implementation, which is directly tested by the new test added in this PR.

Suggested reviewers

  • gaby
  • sixcolors
  • efectn

Poem

In the garden of code, routes once kept their score,
But now the tallies and positions are tracked no more.
Static paths and mounts—together they play,
While tests ensure the files don’t stray.
A bunny hops by, with a cheer so bright:
"Less counting, more serving—everything’s right!"
🐇✨

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 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 3fa8f5e and 8e89e01.

📒 Files selected for processing (1)
  • app.go (0 hunks)
💤 Files with no reviewable changes (1)
  • app.go
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: repeated
  • GitHub Check: Compare
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • Explain this complex logic.
    • 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. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • 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 src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai 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

Documentation and Community

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

@codecov
Copy link

codecov bot commented May 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.10%. Comparing base (fa1f8c9) to head (8e89e01).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3456   +/-   ##
=======================================
  Coverage   84.10%   84.10%           
=======================================
  Files         119      119           
  Lines       11939    11942    +3     
=======================================
+ Hits        10041    10044    +3     
  Misses       1468     1468           
  Partials      430      430           
Flag Coverage Δ
unittests 84.10% <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

@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: 2

🧹 Nitpick comments (2)
middleware/static/static_test.go (1)

853-877: Strengthen the new integration test with content-type & body assertions

Great to see a regression test that mixes mounting, sub-apps, and static files!
To make the test catch more regressions (e.g. MIME-type mis-detection or wrong file served), consider asserting the Content-Type header and a small body snippet:

-	resp, err := app.Test(httptest.NewRequest(fiber.MethodGet, "/static/style.css", nil))
+	req := httptest.NewRequest(fiber.MethodGet, "/static/style.css", nil)
+	resp, err := app.Test(req)
 	require.NoError(t, err, "app.Test(req)")
 	require.Equal(t, 200, resp.StatusCode, "Status code")
+	require.Equal(t, fiber.MIMETextCSSCharsetUTF8, resp.Header.Get(fiber.HeaderContentType))
+
+	body, err := io.ReadAll(resp.Body)
+	require.NoError(t, err)
+	require.Contains(t, string(body), "color")

This keeps the test fast while validating more of the critical behaviour.

router.go (1)

438-462: Duplicate hash-generation logic – factor into a helper and use the existing constant

The 3-byte prefix hash is computed twice in buildTree with the literal 3, while the size constant maxDetectionPaths exists. Re-using a single helper avoids magic numbers and keeps the two loops in sync:

-            if len(route.routeParser.segs[0].Const) >= maxDetectionPaths {
+            if len(route.routeParser.segs[0].Const) >= maxDetectionPaths {
                 prefix := int(route.routeParser.segs[0].Const[0])<<16 |
                     int(route.routeParser.segs[0].Const[1])<<8 |
                     int(route.routeParser.segs[0].Const[2])

Consider extracting:

func treePathHash(b []byte) int {
    if len(b) < maxDetectionPaths {
        return 0
    }
    return int(b[0])<<16 | int(b[1])<<8 | int(b[2])
}

and calling treePathHash(route.routeParser.segs[0].Const) in both loops.
This removes duplication and prevents subtle mismatches if the hashing rule ever changes.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fa1f8c9 and 3fa8f5e.

📒 Files selected for processing (5)
  • middleware/static/static_test.go (1 hunks)
  • mount.go (0 hunks)
  • mount_test.go (0 hunks)
  • router.go (5 hunks)
  • router_test.go (1 hunks)
💤 Files with no reviewable changes (2)
  • mount.go
  • mount_test.go
🧰 Additional context used
🪛 GitHub Check: lint
router_test.go

[failure] 23-23:
var cssDir is unused (unused)

⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: Analyse
  • GitHub Check: unit (1.24.x, windows-latest)
  • GitHub Check: unit (1.23.x, windows-latest)
  • GitHub Check: unit (1.23.x, macos-latest)
  • GitHub Check: repeated
  • GitHub Check: Compare

@ReneWerner87 ReneWerner87 merged commit 119743b into main May 16, 2025
18 checks passed
@github-project-automation github-project-automation bot moved this to Done in v3 May 16, 2025
mdelapenya added a commit to mdelapenya/fiber that referenced this pull request May 19, 2025
* main:
  Update AGENTS.md
  Create AGENTS.md
  🐛 bug: fix redirection flash messages violate cookie structure (gofiber#3457)
  build(deps): bump codecov/codecov-action from 5.4.2 to 5.4.3
  🚀 Improve routing treeBuild flow (gofiber#3456)
  build(deps): bump github.com/tinylib/msgp from 1.2.5 to 1.3.0 (gofiber#3447)
  build(deps): bump DavidAnson/markdownlint-cli2-action from 19 to 20
  🔥 feat: Add All method to Bind (gofiber#3373)
  📝 docs: Document usage of Custom Tags in Logger middleware (gofiber#3446)
@ReneWerner87 ReneWerner87 deleted the mountAppWithStaticV3 branch July 30, 2025 07:11
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