1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
package sockjs
import (
"net/http"
"regexp"
)
type mapping struct {
method string
path *regexp.Regexp
chain []http.HandlerFunc
}
func newMapping(method string, re string, handlers ...http.HandlerFunc) *mapping {
return &mapping{method, regexp.MustCompile(re), handlers}
}
type matchType uint32
const (
fullMatch matchType = iota
pathMatch
noMatch
)
// matches checks if given req.URL is a match with a mapping. Match can be either full, partial (http method mismatch) or no match.
func (m *mapping) matches(req *http.Request) (match matchType, method string) {
if !m.path.MatchString(req.URL.Path) {
match, method = noMatch, ""
} else if m.method != req.Method {
match, method = pathMatch, m.method
} else {
match, method = fullMatch, m.method
}
return
}
|