-
Notifications
You must be signed in to change notification settings - Fork 91
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
feat: add Routes method to support getting all registered routes #995
Conversation
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.
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #995 +/- ##
=======================================
Coverage 70.04% 70.04%
=======================================
Files 168 168
Lines 11353 11355 +2
=======================================
+ Hits 7952 7954 +2
Misses 3050 3050
Partials 351 351 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
||
// Info represents a request route's specification which contains method and path and its handler. | ||
type Info struct { | ||
Method string |
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.
How about defining some constants for this field? User may not know what this is: GET or get?
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.
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.
Okay, if so, string
should be fine. Could you add a comment to this field to tell the user what this field will be like?
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.
Should the Route interface
include a Routes() []Info
method to expose route information?
Recover(recoverFunc func(ctx contractshttp.Context, err any)) | ||
// Routes returns all registered routes. | ||
Routes() []Info |
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.
It will be facades.Route().Routes
, a bit strange. How about List
or something else?
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.
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.
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.
Em, if so, I suggest List
. Any thoughts, please? cc @almas1992
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.
I agree facades.Route().List()
seems more appropriate.
By the way, you can retrieve the method name like For example: func (r *Group) Get(relativePath string, handler httpcontract.HandlerFunc) {
pc := reflect.ValueOf(handler).Pointer()
fn := runtime.FuncForPC(pc)
fmt.Println("fn.Name() ========>", fn.Name())
r.getRoutesWithMiddlewares().GET(
pathToGinPath(relativePath),
[]gin.HandlerFunc{handlerToGinHandler(handler)}...,
)
r.clearMiddlewares()
} Output: fn.Name()=========> goravel/app/http/controllers.(*UserController).Show-fm In other words, the If performance is a concern, one possible optimization is to store |
There is no performance issue, because the routes do not need to be registered frequently. I am considering that this will require many modifications. |
And need to support Group route, which seems not easy too. |
The required changes are indeed a bit extensive. For each routing method—such as A global variable is necessary because if Note: In Gin, computing the full route path for grouped routes requires combining both the originPrefix and prefix fields from the |
I’m wondering whether it’s necessary to build a framework built-in routing system, instead of relying on third-party libraries like Gin or Fiber. Since Go 1.22 introduced built-in routing enhancements, the standard library is now capable of handling routing natively. This would also give us full flexibility to implement structured routing, grouping, middleware, and other features without limitations—allowing the design to better align with the philosophy of our framework. @hwbrzzl
|
Yes, maybe in the future. For now, it should not be our main work, can't give us a lot of benefits. |
Yes, that why I create a new package mux, I want to do some test first. |
Due to my work schedule, I am unable to continue this PR, if anyone is willing, please feel free to take over. |
📑 Description
Closes goravel/goravel#632
✅ Checks