// Match adds a route > handler to the router for multiple HTTP methods provided.
432207
func Match(methods []string, path string, h interface{}, m ...interface{}) {
	Default.Match(methods, path, h, m...)
}
959342
func (m IfMatcher) Match(r *http.Request) bool {
	if m.isOr {
		return m.Or(r)
	}
	return m.And(r)
}
581723
func (r *SimpleRouter) Match(ctx context.Context, match *RouteMatch) (bool, context.Context) {
	for _, route := range r.routes {
		var matched bool
		if matched, ctx = route.Match(ctx, match); matched {
			return true, ctx
		}
	}

	return false, ctx
}
469877
func (m MiddlewareFunc) PathMatches(tests ...regexp.Regexp) MiddlewareFunc {
	return func(h HandlerFunc) HandlerFunc {
		return func(c *Context) error {
			for _, test := range tests {
				if test.MatchString(c.Request().URL().Path) {
					return m(h)(c)
				}
			}
			return h(c)
		}
	}
}
78796
func (r *Router) Find(method string, path string, c *Context) HandlerFunc {
	_logger.debug("===Find")
	_logger.debug("method:" + method)
	_logger.debug("path:" + path)
	if path[0] == '/' && len(path) > 1 {
		path = path[1:]
	}

	currentNode := r.tree.rootNode
	if path == "/" {
		return currentNode.findHandler(method)
	}

	pathArray := strings.Split(path, "/")
	count := len(pathArray)

	pathParams := make(map[int][]Param)
	var paramsNum int

	for index, element := range pathArray {
		// find static node first
		childNode := currentNode.findChildByName(element)

		if childNode == nil {
			// looking for parameter node
			childNode = currentNode.findChildByKind(pkind)

			if childNode != nil {
				_logger.debugf("parameter node: %s", element)
				var newParams []Param
				for _, pName := range childNode.pNames {
					param := Param{Key: pName, Value: element}
					newParams = append(newParams, param)
				}
				pathParams[paramsNum] = newParams
				paramsNum++
			}
		}

		if childNode == nil {
			// looking for match any node
			childNode = currentNode.findChildByKind(akind)

			if childNode != nil {
				_logger.debugf("match node: %s", element)
				start := 0
				for i := 0; i < index; i++ {
					start += 1 + len(pathArray[i])
				}
				_logger.debugf("start: %d", start)
				_logger.debugf("pname count: %d", len(childNode.pNames))
				var newParams []Param
				for _, pName := range childNode.pNames {
					val := path[start:]
					_logger.debugf("val: %s", val)
					param := Param{Key: pName, Value: val}
					newParams = append(newParams, param)
				}
				pathParams[paramsNum] = newParams
				paramsNum++

				index = count - 1
			}
		}

		if childNode == nil {
			//return notFoundHandler
			return nil
		}

		// last node in the path
		if count == index+1 {
			myHandler := childNode.findHandler(method)
			if myHandler == nil {
				//return notFoundHandler
				_logger.debug("handler was not found")
				return nil
			}

			// var newParams []Param
			// for _, pName := range childNode.pNames {
			// 	param := Param{Key: pName, Value: element}
			// 	newParams = append(newParams, param)
			// }
			// pathParams[paramsNum] = newParams
			// paramsNum++

			paramsNum = 0
			//println("params_count:", len(pathParams))
			_logger.debug("lastNode_params_count:", len(childNode.params))
			for _, validParam := range childNode.params {
				for _, p := range pathParams[paramsNum] {
					if validParam == p.Key {
						_logger.debug("matched: " + validParam + "," + p.Value)
						c.params = append(c.params, p)
					}
				}
				paramsNum++
			}

			return myHandler
		}

		currentNode = childNode
	}
	//return notFoundHandler
	return nil
}
474842
func MatchesMethod(r *http.Request, m Method) bool {
	return r.Method == m.String()
}
1206813
func (r *Router) Find(method, path string) (handlers []Handler, params map[string]string) {
	pvalues := make([]string, r.maxParams)
	handlers, pnames := r.find(method, path, pvalues)
	params = make(map[string]string, len(pnames))
	for i, n := range pnames {
		params[n] = pvalues[i]
	}
	return handlers, params
}
238877
func (s *SimpleRule) Match(r *http.Request) bool {
	matches := regexpMatches(s.Regexp, "/", r.URL.Path)
	if s.Negate {
		return len(matches) == 0
	}
	return len(matches) > 0
}
510123
func (r *Router) Get(pattern string, handler http.HandlerFunc) {
	r.AddRoute(GET, pattern, handler)
}
707504
func (r *Router) Handler(method string, path string, handler http.Handler) {
	r.Router.Handler(method, path, handler)
}
713354
func (r *Router) Handle(path string, handler http.Handler, httpMethods ...string) *Trie {
	var version string
	if i := strings.Index(path, "#"); i != -1 {
		version = path[i+1:]
		path = path[:i]
	}
	pathParts := r.splitPath(path)

	// search for dynamic routes
	for _, p := range pathParts {
		if strings.HasPrefix(p, ":") {
			if _, ok := r.dynamicRoutes[p]; !ok {
				r.err = fmt.Errorf("[%s] not found, need to add it using AddRegex(%q, `your regex`", p, p)
				return nil
			}
		}
	}

	// if no methods, accept ALL
	methods := "ALL"
	if len(httpMethods) > 0 && len(strings.TrimSpace(httpMethods[0])) > 0 {
		methods = httpMethods[0]
	}

	if r.Verbose {
		log.Printf("Adding path: %s [%s] %s", path, methods, version)
	}

	trie, err := r.routes.Set(pathParts, handler, methods, version)
	if err != nil {
		r.err = err
		return nil
	}
	return trie
}
128720
func (g *routeGroup) Handle(method string, path string, h ...Handler) {
	g.handle(method, path, h)
}
1335617
func (router *router) match(req *Request) (*Route, error) {
	// todo: consider using goroutines for searching for route

	method := req.Method
	path := req.URL.Path

	for _, route := range router.routes[method] {
		params, err := route.regex.Match(path)

		if err == nil {
			req.Params = params
			return &route, nil
		}
	}

	return nil, errors.New("[" + req.Method + "] handler for route " + path + " not found")
}
1041136
func (m *Mocker) Match(req *http.Request) (bool, error) {
	if m.disabled {
		return false, nil
	}

	// Filter
	for _, filter := range m.request.Filters {
		if !filter(req) {
			return false, nil
		}
	}

	// Map
	for _, mapper := range m.request.Mappers {
		if treq := mapper(req); treq != nil {
			req = treq
		}
	}

	// Match
	matches, err := m.matcher.Match(req, m.request)
	if matches {
		m.decrement()
	}

	return matches, err
}
1060351
func (w *Wildmatch) Match(t string) bool {
	dirs, ok := w.consume(t, MatchOpts{})
	if !ok {
		return false
	}
	return len(dirs) == 0
}
372539
func (r *Router) Handle(method, path string, handlers []HandlerFunc) {
	handlers = r.combineHandlers(handlers)
	r.ace.httprouter.Handle(method, r.path(path), func(w http.ResponseWriter, req *http.Request, params httprouter.Params) {
		c := r.ace.createContext(w, req)
		c.params = params
		c.handlers = handlers
		c.Next()
		r.ace.pool.Put(c)
	})
}
75217
func (n *pathNode) match(path JsonPath) *pathNode {
	var node *pathNode = n
	for _, ps := range path {
		found := false
		for i, n := range node.childNodes {
			if n.matchOn == ps {
				node = &node.childNodes[i]
				found = true
				break
			} else if _, ok := ps.(int); ok && n.matchOn == AnyIndex {
				node = &node.childNodes[i]
				found = true
				break
			}
		}
		if !found {
			return nil
		}
	}
	return node
}