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

Method handle

mux.go:416–437  ·  view source on GitHub ↗

handle registers a http.Handler in the routing tree for a particular http method and routing pattern.

(method methodTyp, pattern string, handler http.Handler)

Source from the content-addressed store, hash-verified

414// handle registers a http.Handler in the routing tree for a particular http method
415// and routing pattern.
416func (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.

Callers 12

HandleMethod · 0.95
MethodMethod · 0.95
ConnectMethod · 0.95
DeleteMethod · 0.95
GetMethod · 0.95
HeadMethod · 0.95
OptionsMethod · 0.95
PatchMethod · 0.95
PostMethod · 0.95
PutMethod · 0.95
TraceMethod · 0.95
MountMethod · 0.95

Calls 5

updateRouteHandlerMethod · 0.95
ChainFunction · 0.85
HandlerFuncMethod · 0.80
InsertRouteMethod · 0.80
HandlerMethod · 0.45

Tested by

no test coverage detected