-
Notifications
You must be signed in to change notification settings - Fork 8k
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
get matched route from context #1390
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1390 +/- ##
==========================================
+ Coverage 98.74% 98.74% +<.01%
==========================================
Files 38 38
Lines 2144 2151 +7
==========================================
+ Hits 2117 2124 +7
Misses 15 15
Partials 12 12
Continue to review full report at Codecov.
|
any updates on this? Would be super useful to have (particularly for middlewares in my case) |
would love to have update on this, as this will be helpful in my code :) |
This PR seems similar to pull request #1447. |
@appleboy / @thinkerou what would be required to get the ball rolling on this pull request? Would love to see this change in production, just interested if I can perhaps run benchmarks or other work to speed things up here. |
@youngblood @isgj @drsect0r please help us review the pr, thanks! |
Add test to check if the route is in the context
@4396 Thank you! @thinkerou would you have time to review? |
so, I would like to know when will this pr will be merged ? it's really useful for me. |
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.
LGTM
Any idea when these changes might get merged? I could really use this for my middleware. Thanks. |
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.
benchmark have some change. hold.
@4396 @drsect0r @isgj @Jim-Lambert-Bose The master branch benchmark data:
And the pull request benchmark data:
cc @appleboy |
@thinkerou probably the reason of allocating those bytes is #1390 (comment) |
@isgj but #1447 also add time, double! see #1447 (comment) |
@thinkerou that's because of the diff --git a/tree.go b/tree.go
index a0e1406..cb8814d 100644
--- a/tree.go
+++ b/tree.go
@@ -376,9 +376,6 @@ func (n *node) insertChild(numParams uint8, path string, fullPath string, handle
// given path.
func (n *node) getValue(path string, po Params, unescape bool) (handlers HandlersChain, p Params, relativePath string, tsr bool) {
p = po
- defer func() {
- relativePath = n.fullPath
- }()
walk: // Outer loop for walking the tree
for {
if len(path) > len(n.path) {
@@ -400,6 +397,7 @@ walk: // Outer loop for walking the tree
// We can recommend to redirect to the same URL without a
// trailing slash if a leaf exists for that path.
tsr = path == "/" && n.handlers != nil
+ relativePath = n.fullPath
return
}
@@ -440,10 +438,12 @@ walk: // Outer loop for walking the tree
// ... but we can't
tsr = len(path) == end+1
+ relativePath = n.fullPath
return
}
if handlers = n.handlers; handlers != nil {
+ relativePath = n.fullPath
return
}
if len(n.children) == 1 {
@@ -452,7 +452,7 @@ walk: // Outer loop for walking the tree
n = n.children[0]
tsr = n.path == "/" && n.handlers != nil
}
-
+ relativePath = n.fullPath
return
case catchAll:
@@ -473,6 +473,7 @@ walk: // Outer loop for walking the tree
}
handlers = n.handlers
+ relativePath = n.fullPath
return
default:
@@ -483,11 +484,13 @@ walk: // Outer loop for walking the tree
// We should have reached the node containing the handle.
// Check if this node has a handle registered.
if handlers = n.handlers; handlers != nil {
+ relativePath = n.fullPath
return
}
if path == "/" && n.wildChild && n.nType != root {
tsr = true
+ relativePath = n.fullPath
return
}
@@ -498,10 +501,11 @@ walk: // Outer loop for walking the tree
n = n.children[i]
tsr = (len(n.path) == 1 && n.handlers != nil) ||
(n.nType == catchAll && n.children[0].handlers != nil)
+ relativePath = n.fullPath
return
}
}
-
+ relativePath = n.fullPath
return
}
@@ -510,6 +514,7 @@ walk: // Outer loop for walking the tree
tsr = (path == "/") ||
(len(n.path) == len(path)+1 && n.path[len(path)] == '/' &&
path == n.path[:len(n.path)-1] && n.handlers != nil)
+ relativePath = n.fullPath
return
}
} the results are the same as |
Hi, thank you for this! It would make things much easier on the instrumentation and reporting side. |
Bump. |
Does anyone have an interest in this? We can get it in shape to get it merged (remove the conflicts) if this is likely to be accepted. |
What about this PR? it could be great for example for statistics usage, to be able to group requests instead of having response time by endpoint and path parameters. |
@denouche which PR? @tompave-roo I have interest in it I just haven't had time to do anything. I went ahead and pulled the more ugly stack overflow example into my codebase and moved on. |
The ticket says it needs to be up to date with master which is what the
others are asking... If you have time and interest of suggest you do that.
…On Wed, Apr 10, 2019, 04:10 Antoine Leveugle ***@***.***> wrote:
This PR, the #390 <#390> @gaffo
<https://github.com/gaffo>
I mean, is it planned to merge it?
Thanks!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1390 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAAvLMY7qqQZjOKGUfro3HF1_qmT78ISks5vfcafgaJpZM4UjxfN>
.
|
The pull request benchmark data:
|
About the pull request which mentions proposal please see #1826 (comment), if you have any suggestion please ping me, thanks! |
ref: #748
Get matched route from context to count the number of calls to the interface or to control user permissions.