-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
API to return matched router path #139
Conversation
d31a9b1
to
c4d72b3
Compare
My $0.02: Love the idea, and have a totally hack logger in place that this would make a million times better, but maybe it could just be a new method on Params that just returns a string? |
@jharlap because |
tree_test.go
Outdated
t.Errorf("handle mismatch for route %q: Wrong handle (%q != %q)", request.path, matchPath, request.route) | ||
} | ||
if matchPath != fakeHandlerValue { | ||
t.Errorf("handler missmatc for route %q: (%q != %q)", request.path, matchPath, fakeHandlerValue) |
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.
missmatc > mismatch
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.
you know me. always trying to sneak in some typos.
c4d72b3
to
f17f139
Compare
@julienschmidt hoping to get some feedback on this! Thanks! |
@julienschmidt This is really a much needed feature. Can you please provide some sort of feedback here? |
I have a fork with this feature here: https://github.com/laplaceon/httprouter. You can see it in action here: https://github.com/laplaceon/polyhedron. |
@julienschmidt Could you please take a look at this again? Having this would be really great when measuring endpoints with prometheus. 🙏 |
I only saw this PR after I started to open mine, but I took a slightly different stab at this as well. Mine doesn't effect the Lookup method signature and exposes the route to your handlers through the request context. |
@julienschmidt do you have any feedback on this or #286? I'd be happy to take any design or implementation feedback and update this PR. This has been very useful for me since i've opened this PR a few years ago and i'd love to contribute this upstream. |
I gave some feedback over here: #286 (comment) |
I would like to propose an API that returns the exact router path that's been matched. There are multiple situations where having the router path available would be beneficial like logging, rate limiting, etc because it will have less cardinality than the full URL with dynamic parameters.
Given the following example
I'd like to store the state of the full route being matched in each
node
of the match tree and add arouter.LookupRoute()
(to avoid a backwards incompatible change toLookup()
) so that you can re-parse the request path and find which route matched. I'm open to other naming suggestions, or if you'd rather make a breaking change toLookup
and add the return value there.