MCPcopy
hub / github.com/grafana/dskit / getRouteName

Function getRouteName

middleware/route_injector.go:52–76  ·  view source on GitHub ↗
(routeMatcher RouteMatcher, r *http.Request)

Source from the content-addressed store, hash-verified

50}
51
52func getRouteName(routeMatcher RouteMatcher, r *http.Request) string {
53 var routeMatch mux.RouteMatch
54 if routeMatcher == nil || !routeMatcher.Match(r, &routeMatch) {
55 return ""
56 }
57
58 if routeMatch.MatchErr == mux.ErrNotFound {
59 return "notfound"
60 }
61
62 if routeMatch.Route == nil {
63 return ""
64 }
65
66 if name := routeMatch.Route.GetName(); name != "" {
67 return name
68 }
69
70 tmpl, err := routeMatch.Route.GetPathTemplate()
71 if err == nil {
72 return MakeLabelValue(tmpl)
73 }
74
75 return ""
76}
77
78var invalidChars = regexp.MustCompile(`[^a-zA-Z0-9]+`)
79

Callers 3

WrapMethod · 0.85

Calls 2

MakeLabelValueFunction · 0.85
MatchMethod · 0.80

Tested by

no test coverage detected