-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
🚀 Improve routing treeBuild flow #3456
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
Conversation
WalkthroughThis 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
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
Possibly related PRs
Suggested reviewers
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit 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. Note ⚡️ Faster reviews with cachingCodeRabbit 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 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
💤 Files with no reviewable changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (4)
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this 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 assertionsGreat 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 theContent-Typeheader 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 constantThe 3-byte prefix hash is computed twice in
buildTreewith the literal3, while the size constantmaxDetectionPathsexists. 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
📒 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
* 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)
Adoption of the better logic for building the routing tree from the v2 bug fix #3454