Added trailing slash for static routes
This commit is contained in:
parent
0323126f2c
commit
a7d64037a7
8 changed files with 119 additions and 96 deletions
11
treeNode.go
11
treeNode.go
|
@ -157,6 +157,7 @@ func (node *treeNode[T]) append(path string, data T) {
|
|||
if node.prefix == "" {
|
||||
node.prefix = path
|
||||
node.data = data
|
||||
node.addTrailingSlash(data)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -229,7 +230,7 @@ func (node *treeNode[T]) append(path string, data T) {
|
|||
// end is called when the node was fully parsed
|
||||
// and needs to decide the next control flow.
|
||||
// end is only called from `tree.Add`.
|
||||
func (node *treeNode[T]) end(path string, data T, i int, offset int) (*treeNode[T], int, controlFlow) {
|
||||
func (node *treeNode[T]) end(path string, data T, i int, offset int) (*treeNode[T], int, flow) {
|
||||
char := path[i]
|
||||
|
||||
if char >= node.startIndex && char < node.endIndex {
|
||||
|
@ -238,7 +239,7 @@ func (node *treeNode[T]) end(path string, data T, i int, offset int) (*treeNode[
|
|||
if index != 0 {
|
||||
node = node.children[index]
|
||||
offset = i
|
||||
return node, offset, controlNext
|
||||
return node, offset, flowNext
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,7 +247,7 @@ func (node *treeNode[T]) end(path string, data T, i int, offset int) (*treeNode[
|
|||
// If no prefix is set, this is the starting node.
|
||||
if node.prefix == "" {
|
||||
node.append(path[i:], data)
|
||||
return node, offset, controlStop
|
||||
return node, offset, flowStop
|
||||
}
|
||||
|
||||
// node: /user/|:id
|
||||
|
@ -254,11 +255,11 @@ func (node *treeNode[T]) end(path string, data T, i int, offset int) (*treeNode[
|
|||
if node.parameter != nil && path[i] == parameter {
|
||||
node = node.parameter
|
||||
offset = i
|
||||
return node, offset, controlBegin
|
||||
return node, offset, flowBegin
|
||||
}
|
||||
|
||||
node.append(path[i:], data)
|
||||
return node, offset, controlStop
|
||||
return node, offset, flowStop
|
||||
}
|
||||
|
||||
// each traverses the tree and calls the given function on every node.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue