Is there a way to get the name of current route?
puper opened this issue · 2 comments
puper commented
Im want to do some permission check in middleware.
abdrd commented
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 commented
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