Sfoglia il codice sorgente

Updates tree.go from httpRouter

Manu Mtz.-Almeida 9 anni fa
parent
commit
20825e7694
1 ha cambiato i file con 10 aggiunte e 3 eliminazioni
  1. 10 3
      tree.go

+ 10 - 3
tree.go

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