HasRoute checks whether the specified route pattern (method + path) is registered in the current group or its children. This could be useful to conditionally register and checks for routes in order prevent panic on duplicated routes. Note that routes with anonymous and named wildcard placeholder a
(method string, path string)
| 181 | // Note that routes with anonymous and named wildcard placeholder are treated as equal, |
| 182 | // aka. "GET /abc/" is considered the same as "GET /abc/{something...}". |
| 183 | func (group *RouterGroup[T]) HasRoute(method string, path string) bool { |
| 184 | pattern := path |
| 185 | if method != "" { |
| 186 | pattern = strings.ToUpper(method) + " " + pattern |
| 187 | } |
| 188 | |
| 189 | return group.hasRoute(pattern, nil) |
| 190 | } |
| 191 | |
| 192 | func (group *RouterGroup[T]) hasRoute(pattern string, parents []*RouterGroup[T]) bool { |
| 193 | for _, child := range group.children { |