MCPcopy
hub / github.com/pocketbase/pocketbase / HasRoute

Method HasRoute

tools/router/group.go:183–190  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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...}".
183func (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
192func (group *RouterGroup[T]) hasRoute(pattern string, parents []*RouterGroup[T]) bool {
193 for _, child := range group.children {

Callers 3

BuildMuxMethod · 0.80
TestRouterGroupHasRouteFunction · 0.80
mainFunction · 0.80

Calls 1

hasRouteMethod · 0.95

Tested by 1

TestRouterGroupHasRouteFunction · 0.64