mux.go
func (mx *Mux) routeHTTP(w http.ResponseWriter, r *http.Request) {
	// Grab the route context object
	rctx := r.Context().Value(RouteCtxKey).(*Context)

	// The request routing path
	routePath := rctx.RoutePath
	if routePath == "" {
		if r.URL.RawPath != "" {
			routePath = r.URL.RawPath
		} else {
			routePath = r.URL.Path
		}
	}

	// Check if method is supported by chi
	if rctx.RouteMethod == "" {
		rctx.RouteMethod = r.Method
	}
	method, ok := methodMap[rctx.RouteMethod]
	if !ok {
		mx.MethodNotAllowedHandler().ServeHTTP(w, r)
		return
	}

	// Find the route
	if _, _, h := mx.tree.FindRoute(rctx, method, routePath); h != nil {
		h.ServeHTTP(w, r)
		return
	}
	if rctx.methodNotAllowed {
		mx.MethodNotAllowedHandler().ServeHTTP(w, r)
	} else {
		mx.NotFoundHandler().ServeHTTP(w, r)
	}
}
func (mx *Mux) routeHTTP(w http.ResponseWriter, r *http.Request) {
	// Grab the route context object
	rctx := r.Context().Value(RouteCtxKey).(*Context)

	// The request routing path
	routePath := rctx.RoutePath
	if routePath == "" {
		if r.URL.RawPath != "" {
			routePath = r.URL.RawPath
		} else {
			routePath = r.URL.Path
		}
	}

	// Check if method is supported by chi
	if rctx.RouteMethod == "" {
		rctx.RouteMethod = r.Method
	}
	method, ok := methodMap[rctx.RouteMethod]
	if !ok {
		mx.MethodNotAllowedHandler().ServeHTTP(w, r)
		return
	}

	// Find the route
	if _, _, h := mx.tree.FindRoute(rctx, method, routePath); h != nil {
		h.ServeHTTP(w, r)
		return
	}
	if rctx.methodNotAllowed {
		mx.MethodNotAllowedHandler().ServeHTTP(w, r)
	} else {
		mx.NotFoundHandler().ServeHTTP(w, r)
	}
}
func ( mx * Mux ) routeHTTP ( w http . ResponseWriter , r * http . Request ) { // Grab the route context object rctx := r . Context ( ) . Value ( RouteCtxKey ) . ( * Context ) // The request routing path routePath := rctx . RoutePath if routePath == " " { if r . URL . RawPath != " " { routePath = r . URL . RawPath } else { routePath = r . URL . Path } } // Check if method is supported by chi if rctx . RouteMethod == " " { rctx . RouteMethod = r . Method } method , ok := methodMap [ rctx . RouteMethod ] if ! ok { mx . MethodNotAllowedHandler ( ) . ServeHTTP ( w , r ) return } // Find the route if _ , _ , h := mx . tree . FindRoute ( rctx , method , routePath ) ; h != nil { h . ServeHTTP ( w , r ) return } if rctx . methodNotAllowed { mx . MethodNotAllowedHandler ( ) . ServeHTTP ( w , r ) } else { mx . NotFoundHandler ( ) . ServeHTTP ( w , r ) } }
// routeHTTP routes a http.Request through the Mux routing tree to serve
// the matching handler for a particular http method.
routeHTTP routes a http . Request through the Mux routing tree to serve the matching handler for a particular http method .