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)
| 136 | // (eg: not found) has a registered handler, the handler is assigned to the Handler |
| 137 | // field of the match argument. |
| 138 | func (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 | // |