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)
| 366 | // Note: the *Context state is updated during execution, so manage |
| 367 | // the state carefully or make a NewRouteContext(). |
| 368 | func (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. |
no test coverage detected