if non wildcard is nil, try wildcard route
parent
32326de6b2
commit
5deb0e5f0d
|
|
@ -24,12 +24,24 @@ func newTree() *tree {
|
||||||
|
|
||||||
func (t *tree) Lookup(path string) http.HandlerFunc {
|
func (t *tree) Lookup(path string) http.HandlerFunc {
|
||||||
if path == "/" || path == "" {
|
if path == "/" || path == "" {
|
||||||
return t.handler
|
if t.handler != nil {
|
||||||
|
return t.handler
|
||||||
|
}
|
||||||
|
if n, ok := t.next[Wildcard+Wildcard]; t.handler == nil && ok {
|
||||||
|
foo := n.handler
|
||||||
|
return foo
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
key, following := nextPathSegment(path)
|
key, following := nextPathSegment(path)
|
||||||
if n, ok := t.next[key]; ok {
|
n, ok := t.next[key]
|
||||||
return n.Lookup(following)
|
if ok {
|
||||||
} else if n, ok := t.next[Wildcard]; ok {
|
n2 := n.Lookup(following)
|
||||||
|
if n2 != nil {
|
||||||
|
return n2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if n, ok := t.next[Wildcard]; ok {
|
||||||
foo := n.Lookup(following)
|
foo := n.Lookup(following)
|
||||||
if foo != nil {
|
if foo != nil {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
@ -37,6 +49,14 @@ func (t *tree) Lookup(path string) http.HandlerFunc {
|
||||||
foo(w, r)
|
foo(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if n, ok := t.next[Wildcard+Wildcard]; ok {
|
||||||
|
foo := n.handler
|
||||||
|
if foo != nil {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
r.Header.Add(WildcardHeader, key)
|
||||||
|
foo(w, r)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue