@@ -11,8 +11,8 @@ import "net/url"
1111type nodeType uint8
1212
1313const (
14- isStatic nodeType = iota // default
15- isRoot
14+ // isStatic nodeType = iota // default
15+ isRoot nodeType = iota + 1
1616 hasParams
1717 matchesAny
1818)
@@ -26,12 +26,12 @@ type existingParams map[string]struct{}
2626
2727type node struct {
2828 path string
29- wildChild bool
30- nType nodeType
3129 indices string
3230 children []* node
3331 handler * methodChain
3432 priority uint32
33+ nType nodeType
34+ wildChild bool
3535}
3636
3737func (e existingParams ) Check (param string , path string ) {
@@ -76,8 +76,8 @@ func (n *node) add(path string, handlerName string, handler HandlersChain) (lp u
7676
7777 var err error
7878
79- if path == "" {
80- path = "/"
79+ if path == blank {
80+ path = basePath
8181 }
8282
8383 existing := make (existingParams )
@@ -140,7 +140,7 @@ func (n *node) add(path string, handlerName string, handler HandlersChain) (lp u
140140 if len (path ) >= len (n .path ) && n .path == path [:len (n .path )] {
141141
142142 // check for longer wildcard, e.g. :name and :names
143- if len (n .path ) >= len (path ) || path [len (n .path )] == '/' {
143+ if len (n .path ) >= len (path ) || path [len (n .path )] == slashByte {
144144 continue walk
145145 }
146146 }
@@ -153,7 +153,7 @@ func (n *node) add(path string, handlerName string, handler HandlersChain) (lp u
153153 c := path [0 ]
154154
155155 // slash after param
156- if n .nType == hasParams && c == '/' && len (n .children ) == 1 {
156+ if n .nType == hasParams && c == slashByte && len (n .children ) == 1 {
157157 n = n .children [0 ]
158158 n .priority ++
159159 continue walk
@@ -214,7 +214,7 @@ func (n *node) insertChild(numParams uint8, existing existingParams, path string
214214
215215 // find wildcard end (either '/' or path end)
216216 end := i + 1
217- for end < max && path [end ] != '/' {
217+ for end < max && path [end ] != slashByte {
218218 switch path [end ] {
219219 // the wildcard name must not contain ':' and '*'
220220 case paramByte , wildByte :
@@ -281,7 +281,7 @@ func (n *node) insertChild(numParams uint8, existing existingParams, path string
281281
282282 // currently fixed width 1 for '/'
283283 i --
284- if path [i ] != '/' {
284+ if path [i ] != slashByte {
285285 panic ("no / before catch-all in path '" + fullPath + "'" )
286286 }
287287
@@ -353,7 +353,7 @@ walk: // Outer loop for walking the tree
353353
354354 // find param end (either '/' or path end)
355355 end := 0
356- for end < len (path ) && path [end ] != '/' {
356+ for end < len (path ) && path [end ] != slashByte {
357357 end ++
358358 }
359359
0 commit comments