handle registers a http.Handler in the routing tree for a particular http method and routing pattern.
(method methodTyp, pattern string, handler http.Handler)
| 414 | // handle registers a http.Handler in the routing tree for a particular http method |
| 415 | // and routing pattern. |
| 416 | func (mx *Mux) handle(method methodTyp, pattern string, handler http.Handler) *node { |
| 417 | if len(pattern) == 0 || pattern[0] != '/' { |
| 418 | panic(fmt.Sprintf("chi: routing pattern must begin with '/' in '%s'", pattern)) |
| 419 | } |
| 420 | |
| 421 | // Build the computed routing handler for this routing pattern. |
| 422 | if !mx.inline && mx.handler == nil { |
| 423 | mx.updateRouteHandler() |
| 424 | } |
| 425 | |
| 426 | // Build endpoint handler with inline middlewares for the route |
| 427 | var h http.Handler |
| 428 | if mx.inline { |
| 429 | mx.handler = http.HandlerFunc(mx.routeHTTP) |
| 430 | h = Chain(mx.middlewares...).Handler(handler) |
| 431 | } else { |
| 432 | h = handler |
| 433 | } |
| 434 | |
| 435 | // Add the endpoint to the tree and return the node |
| 436 | return mx.tree.InsertRoute(method, pattern, h) |
| 437 | } |
| 438 | |
| 439 | // routeHTTP routes a http.Request through the Mux routing tree to serve |
| 440 | // the matching handler for a particular http method. |
no test coverage detected