| 45 | } |
| 46 | |
| 47 | func getRoutePattern(r *http.Request) string { |
| 48 | rctx := chi.RouteContext(r.Context()) |
| 49 | if rctx == nil { |
| 50 | return "" |
| 51 | } |
| 52 | |
| 53 | routePath := r.URL.Path |
| 54 | if r.URL.RawPath != "" { |
| 55 | routePath = r.URL.RawPath |
| 56 | } |
| 57 | |
| 58 | tctx := chi.NewRouteContext() |
| 59 | routes := rctx.Routes |
| 60 | if routes != nil && !routes.Match(tctx, r.Method, routePath) { |
| 61 | // No matching pattern. /api/* requests will be matched as "UNKNOWN" |
| 62 | // All other ones will be matched as "STATIC". |
| 63 | if strings.HasPrefix(routePath, "/api/") { |
| 64 | return "UNKNOWN" |
| 65 | } |
| 66 | return "STATIC" |
| 67 | } |
| 68 | |
| 69 | // tctx has the updated pattern, since Match mutates it |
| 70 | return tctx.RoutePattern() |
| 71 | } |