Skip to content
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

Is there a way to get the name of current route? #40

Open
puper opened this issue Sep 5, 2017 · 2 comments
Open

Is there a way to get the name of current route? #40

puper opened this issue Sep 5, 2017 · 2 comments

Comments

@puper
Copy link

puper commented Sep 5, 2017

Im want to do some permission check in middleware.

@abdrd
Copy link

abdrd commented Dec 30, 2021

I don't use this package, but by looking at the source code, I can say you can get the request path using this:

func yourController(c *routing.Context) {
     path := c.Request.URL.Path
     c.Write(fmt.Sprintf("you hit %s", path))
}

@fedulovivan
Copy link

I came here searching some API to obtain current route pattern from context, istead of actual URL being handled.
In my case the intention is switching to collection of per-route statistics without taking into account actual route param values.
This will make prometheus counters look like

mhz19_api_requests{method="GET",path="/api/messages/device/<deviceId>"} 12
mhz19_api_requests{method="GET",path="/api/stats"} 2

instead of

mhz19_api_requests{method="GET",path="/api/messages/device/0x00158d00067cb0c9"} 5
mhz19_api_requests{method="GET",path="/api/messages/device/0x56hh111"} 7
mhz19_api_requests{method="GET",path="/api/stats"} 2

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

No branches or pull requests

3 participants