MCPcopy
hub / github.com/go-chi/chi / Find

Method Find

mux.go:368–394  ·  view source on GitHub ↗

Find searches the routing tree for the pattern that matches the method/path. Note: the *Context state is updated during execution, so manage the state carefully or make a NewRouteContext().

(rctx *Context, method, path string)

Source from the content-addressed store, hash-verified

366// Note: the *Context state is updated during execution, so manage
367// the state carefully or make a NewRouteContext().
368func (mx *Mux) Find(rctx *Context, method, path string) string {
369 m, ok := methodMap[method]
370 if !ok {
371 return ""
372 }
373
374 node, _, _ := mx.tree.FindRoute(rctx, m, path)
375 pattern := rctx.routePattern
376
377 if node != nil {
378 if node.subroutes == nil {
379 e := node.endpoints[m]
380 return e.pattern
381 }
382
383 rctx.RoutePath = mx.nextRoutePath(rctx)
384 subPattern := node.subroutes.Find(rctx, method, rctx.RoutePath)
385 if subPattern == "" {
386 return ""
387 }
388
389 pattern = strings.TrimSuffix(pattern, "/*")
390 pattern += subPattern
391 }
392
393 return pattern
394}
395
396// NotFoundHandler returns the default Mux 404 responder whenever a route
397// cannot be found.

Callers 1

MatchMethod · 0.95

Calls 3

nextRoutePathMethod · 0.95
FindRouteMethod · 0.80
FindMethod · 0.65

Tested by

no test coverage detected