RoutePattern builds the routing pattern string for the particular request, at the particular point during routing. This means, the value will change throughout the execution of a request in a router. That is why it's advised to only use this value after calling the next handler. For example, func
()
| 121 | // }) |
| 122 | // } |
| 123 | func (x *Context) RoutePattern() string { |
| 124 | if x == nil { |
| 125 | return "" |
| 126 | } |
| 127 | routePattern := strings.Join(x.RoutePatterns, "") |
| 128 | routePattern = replaceWildcards(routePattern) |
| 129 | if routePattern != "/" { |
| 130 | routePattern = strings.TrimSuffix(routePattern, "//") |
| 131 | routePattern = strings.TrimSuffix(routePattern, "/") |
| 132 | } |
| 133 | return routePattern |
| 134 | } |
| 135 | |
| 136 | // replaceWildcards takes a route pattern and replaces all occurrences of |
| 137 | // "/*/" with "/". It iteratively runs until no wildcards remain to |