@@ -81,7 +81,9 @@ func (t *tree) searchByParts(parent *node, parts []string, position int, paramet
8181 return child
8282 }
8383
84- return t .searchByParts (child , parts , position + 1 , parameters )
84+ if node := t .searchByParts (child , parts , position + 1 , parameters ); node != nil {
85+ return node
86+ }
8587 }
8688 }
8789
@@ -106,16 +108,16 @@ func (t *tree) searchByName(node *node, name string) *node {
106108}
107109
108110// insert adds a new route to the radix tree by recursive traversing.
109- func (t * tree ) insert (parent , node * node , parts []string , index int ) {
110- isLeaf := index == len (parts )- 1
111+ func (t * tree ) insert (parent , node * node , parts []string , position int ) {
112+ isLeaf := position == len (parts )- 1
111113
112114 for i , child := range parent .Children {
113- if child .content == parts [index ] {
115+ if child .content == parts [position ] {
114116 if isLeaf {
115117 node .Children = parent .Children [i ].Children
116118 parent .Children [i ] = node
117119 } else {
118- t .insert (child , node , parts , index + 1 )
120+ t .insert (child , node , parts , position + 1 )
119121 }
120122 return
121123 }
@@ -124,9 +126,9 @@ func (t *tree) insert(parent, node *node, parts []string, index int) {
124126 if isLeaf {
125127 parent .Children = append (parent .Children , node )
126128 } else {
127- newNode := newNode (nil , parts [index ])
129+ newNode := newNode (nil , parts [position ])
128130 parent .Children = append (parent .Children , newNode )
129- t .insert (newNode , node , parts , index + 1 )
131+ t .insert (newNode , node , parts , position + 1 )
130132 }
131133}
132134
0 commit comments