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

Method FindRoute

tree.go:374–397  ·  view source on GitHub ↗
(rctx *Context, method methodTyp, path string)

Source from the content-addressed store, hash-verified

372}
373
374func (n *node) FindRoute(rctx *Context, method methodTyp, path string) (*node, endpoints, http.Handler) {
375 // Reset the context routing pattern and params
376 rctx.routePattern = ""
377 rctx.routeParams.Keys = rctx.routeParams.Keys[:0]
378 rctx.routeParams.Values = rctx.routeParams.Values[:0]
379
380 // Find the routing handlers for the path
381 rn := n.findRoute(rctx, method, path)
382 if rn == nil {
383 return nil, nil, nil
384 }
385
386 // Record the routing params in the request lifecycle
387 rctx.URLParams.Keys = append(rctx.URLParams.Keys, rctx.routeParams.Keys...)
388 rctx.URLParams.Values = append(rctx.URLParams.Values, rctx.routeParams.Values...)
389
390 // Record the routing pattern in the request lifecycle
391 if rn.endpoints[method].pattern != "" {
392 rctx.routePattern = rn.endpoints[method].pattern
393 rctx.RoutePatterns = append(rctx.RoutePatterns, rctx.routePattern)
394 }
395
396 return rn, rn.endpoints, rn.endpoints[method].handler
397}
398
399// Recursive edge traversal by checking all nodeTyp groups along the way.
400// It's like searching through a multi-dimensional radix trie.

Callers 8

TestTreeFunction · 0.95
TestTreeMoarFunction · 0.95
TestTreeRegexpFunction · 0.95
TestTreeRegexpRecursiveFunction · 0.95
BenchmarkTreeGetFunction · 0.95
FindMethod · 0.80
routeHTTPMethod · 0.80

Calls 1

findRouteMethod · 0.95

Tested by 6

TestTreeFunction · 0.76
TestTreeMoarFunction · 0.76
TestTreeRegexpFunction · 0.76
TestTreeRegexpRecursiveFunction · 0.76
BenchmarkTreeGetFunction · 0.76