route wildcards suppoort substr
This commit is contained in:
14
tree.go
14
tree.go
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -57,6 +58,19 @@ func (t *tree) Lookup(path string) http.HandlerFunc {
|
||||
foo(w, r)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for k, n := range t.next {
|
||||
if !strings.Contains(k, Wildcard) {
|
||||
continue
|
||||
}
|
||||
re := regexp.MustCompile(strings.ReplaceAll(k, Wildcard, ".*"))
|
||||
if re.MatchString(key) && n.handler != nil {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Header.Add(WildcardHeader, key)
|
||||
n.handler(w, r)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user