Added trailing slash for static routes
This commit is contained in:
31
Tree.go
31
Tree.go
@ -1,15 +1,5 @@
|
||||
package router
|
||||
|
||||
// controlFlow tells the main loop what it should do next.
|
||||
type controlFlow int
|
||||
|
||||
// controlFlow values.
|
||||
const (
|
||||
controlStop controlFlow = 0
|
||||
controlBegin controlFlow = 1
|
||||
controlNext controlFlow = 2
|
||||
)
|
||||
|
||||
// Tree represents a radix tree.
|
||||
type Tree[T any] struct {
|
||||
root treeNode[T]
|
||||
@ -36,17 +26,8 @@ func (tree *Tree[T]) Add(path string, data T) {
|
||||
|
||||
// When we hit a separator, we'll search for a fitting child.
|
||||
if path[i] == separator {
|
||||
var control controlFlow
|
||||
node, offset, control = node.end(path, data, i, offset)
|
||||
|
||||
switch control {
|
||||
case controlStop:
|
||||
return
|
||||
case controlBegin:
|
||||
goto begin
|
||||
case controlNext:
|
||||
goto next
|
||||
}
|
||||
node, offset, _ = node.end(path, data, i, offset)
|
||||
goto next
|
||||
}
|
||||
|
||||
default:
|
||||
@ -70,15 +51,15 @@ func (tree *Tree[T]) Add(path string, data T) {
|
||||
// node: /|
|
||||
// path: /|blog
|
||||
if i-offset == len(node.prefix) {
|
||||
var control controlFlow
|
||||
var control flow
|
||||
node, offset, control = node.end(path, data, i, offset)
|
||||
|
||||
switch control {
|
||||
case controlStop:
|
||||
case flowStop:
|
||||
return
|
||||
case controlBegin:
|
||||
case flowBegin:
|
||||
goto begin
|
||||
case controlNext:
|
||||
case flowNext:
|
||||
goto next
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user