Updates tree.go from httpRouter

This commit is contained in:
Manu Mtz.-Almeida 2016-01-28 00:14:26 +01:00
parent 8949247b92
commit 20825e7694

13
tree.go
View File

@ -76,9 +76,10 @@ func countParams(path string) uint8 {
type nodeType uint8 type nodeType uint8
const ( const (
static nodeType = 0 static nodeType = iota // default
param nodeType = 1 root
catchAll nodeType = 2 param
catchAll
) )
type node struct { type node struct {
@ -238,6 +239,7 @@ func (n *node) addRoute(path string, handlers HandlersChain) {
} }
} else { // Empty tree } else { // Empty tree
n.insertChild(numParams, path, fullPath, handlers) n.insertChild(numParams, path, fullPath, handlers)
n.nType = root
} }
} }
@ -452,6 +454,11 @@ walk: // Outer loop for walking the tree
return return
} }
if path == "/" && n.wildChild && n.nType != root {
tsr = true
return
}
// No handle found. Check if a handle for this path + a // No handle found. Check if a handle for this path + a
// trailing slash exists for trailing slash recommendation // trailing slash exists for trailing slash recommendation
for i := 0; i < len(n.indices); i++ { for i := 0; i < len(n.indices); i++ {