diff --git a/router.go b/router.go old mode 100644 new mode 100755 diff --git a/router_test.go b/router_test.go old mode 100644 new mode 100755 diff --git a/tree.go b/tree.go old mode 100644 new mode 100755 index cc2ff0d..817bed9 --- a/tree.go +++ b/tree.go @@ -24,12 +24,24 @@ func newTree() *tree { func (t *tree) Lookup(path string) http.HandlerFunc { 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) - if n, ok := t.next[key]; ok { - return n.Lookup(following) - } else if n, ok := t.next[Wildcard]; ok { + n, ok := t.next[key] + if ok { + n2 := n.Lookup(following) + if n2 != nil { + return n2 + } + } + if n, ok := t.next[Wildcard]; ok { foo := n.Lookup(following) if foo != nil { return func(w http.ResponseWriter, r *http.Request) { @@ -37,6 +49,14 @@ func (t *tree) Lookup(path string) http.HandlerFunc { 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 } diff --git a/tree_test.go b/tree_test.go old mode 100644 new mode 100755