MCPcopy
hub / github.com/gorilla/mux / Match

Method Match

mux.go:138–169  ·  mux.go::Router.Match

Match attempts to match the given request against the router's registered routes. If the request matches a route of this router or one of its subrouters the Route, Handler, and Vars fields of the the match argument are filled and this function returns true. If the request does not match any of thi

(req *http.Request, match *RouteMatch)

Source from the content-addressed store, hash-verified

136// (eg: not found) has a registered handler, the handler is assigned to the Handler
137// field of the match argument.
138func (r *Router) Match(req *http.Request, match *RouteMatch) bool {
139 for _, route := range r.routes {
140 if route.Match(req, match) {
141 // Build middleware chain if no error was found
142 if match.MatchErr == nil {
143 for i := len(r.middlewares) - 1; i >= 0; i-- {
144 match.Handler = r.middlewares[i].Middleware(match.Handler)
145 }
146 }
147 return true
148 }
149 }
150
151 if match.MatchErr == ErrMethodMismatch {
152 if r.MethodNotAllowedHandler != nil {
153 match.Handler = r.MethodNotAllowedHandler
154 return true
155 }
156
157 return false
158 }
159
160 // Closest match for a router (includes sub-routers)
161 if r.NotFoundHandler != nil {
162 match.Handler = r.NotFoundHandler
163 match.MatchErr = ErrNotFound
164 return true
165 }
166
167 match.MatchErr = ErrNotFound
168 return false
169}
170
171// ServeHTTP dispatches the handler registered in the matched route.
172//

Callers 9

ServeHTTPMethod · 0.95
TestSubrouterHeaderFunction · 0.95
TestErrMatchNotFoundFunction · 0.95
TestSubrouterMatchingFunction · 0.95
TestRouteMatchersFunction · 0.95
TestMatchedRouteNameFunction · 0.95
TestSubRoutingFunction · 0.95

Calls 2

MatchMethod · 0.65
MiddlewareMethod · 0.65

Tested by 8

TestSubrouterHeaderFunction · 0.76
TestErrMatchNotFoundFunction · 0.76
TestSubrouterMatchingFunction · 0.76
TestRouteMatchersFunction · 0.76
TestMatchedRouteNameFunction · 0.76
TestSubRoutingFunction · 0.76