Skip to content

Add support for SubRouter - #70

Merged
tigerwill90 merged 29 commits into
masterfrom
feat/subrouter
Dec 30, 2025
Merged

tigerwill90 merged 29 commits into
masterfrom
feat/subrouter

Conversation

@tigerwill90

@tigerwill90 tigerwill90 commented Dec 9, 2025 •

Copy link
Copy Markdown
Collaborator

Summary

This PR introduces several significant features and improvements to the Fox router:

  • SubRouter Support: Enable nested routing by mounting sub-routers with pattern prefixes, allowing modular route composition
  • Optional Named Wildcards (+{param}): New catch-all syntax that matches any sequence of characters including empty strings, useful for optional path suffixes
  • Method-less Routes (fox.MethodAny): Register routes that match any HTTP method, with specific methods taking precedence (this is only a transition, next PR will use matchers for matching methods)
  • Context API Refactoring: Replace Context interface with concrete *Context type (which also was a requirement for the SubRouter feature). This should slightly improve the performance.

Example

api := fox.MustNew()
api.MustHandle(http.MethodGet, "/", func(c *fox.Context) {
	_ = c.String(http.StatusOK, "Welcome")
})
api.MustHandle(http.MethodGet, "/users/{id}", func(c *fox.Context) {
	_ = c.String(http.StatusOK, fmt.Sprintf("Hello %s\n", c.Param("id")))
})

f := fox.MustNew(fox.DefaultOptions())
route, err := f.NewSubRouter("/api+{any}", api)
if err != nil {
	panic(err)
}
if err := f.HandleRoute(MethodAny, route); err != nil {
	panic(err)
}

@codecov

codecov Bot commented Dec 9, 2025 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 82.29572% with 91 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.89%. Comparing base (f4c530a) to head (a211c2e).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
fox.go 85.66% 34 Missing and 11 partials ⚠️
error.go 12.50% 14 Missing ⚠️
txn.go 29.41% 12 Missing ⚠️
tree.go 79.48% 5 Missing and 3 partials ⚠️
context.go 88.52% 4 Missing and 3 partials ⚠️
route.go 33.33% 4 Missing ⚠️
recovery.go 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #70      +/-   ##
==========================================
- Coverage   89.98%   88.89%   -1.09%     
==========================================
  Files          25       25              
  Lines        3836     4135     +299     
==========================================
+ Hits         3452     3676     +224     
- Misses        296      359      +63     
- Partials       88      100      +12     

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

@tigerwill90
tigerwill90 requested a review from pawndev December 28, 2025 23:48
@tigerwill90 tigerwill90 self-assigned this Dec 28, 2025
@tigerwill90
tigerwill90 marked this pull request as ready for review December 30, 2025 14:02
@tigerwill90
tigerwill90 merged commit fea3c6c into master Dec 30, 2025
7 of 9 checks passed
@tigerwill90
tigerwill90 deleted the feat/subrouter branch December 30, 2025 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant