Updated some comments
This commit is contained in:
parent
872fd98c14
commit
1bd1a884c4
|
@ -21,8 +21,8 @@ router.Add("GET", "/hello", "...")
|
|||
router.Add("GET", "/world", "...")
|
||||
|
||||
// Parameter routes
|
||||
router.Add("GET", "/users/:id", "...")
|
||||
router.Add("GET", "/users/:id/comments", "...")
|
||||
router.Add("GET", "/users/[id]", "...")
|
||||
router.Add("GET", "/users/[id]/comments", "...")
|
||||
|
||||
// Wildcard routes
|
||||
router.Add("GET", "/images/*path", "...")
|
||||
|
|
9
tree.go
9
tree.go
|
@ -1,13 +1,12 @@
|
|||
package router
|
||||
|
||||
// Super-fancy radix tree
|
||||
// Representation of a node tree
|
||||
type Tree[T any] struct {
|
||||
root Node[T]
|
||||
}
|
||||
|
||||
// Adds a new element to the tree
|
||||
// Adds a new path to the tree
|
||||
func (tree *Tree[T]) Add(path string, data T) {
|
||||
// Search tree for equal parts until we can no longer proceed
|
||||
i := 0
|
||||
offset := 0
|
||||
node := &tree.root
|
||||
|
@ -17,8 +16,8 @@ func (tree *Tree[T]) Add(path string, data T) {
|
|||
switch node.kind {
|
||||
case parameter:
|
||||
// This only occurs when the same parameter based route is added twice.
|
||||
// node: /post/:id|
|
||||
// path: /post/:id|
|
||||
// node: /post/[id|
|
||||
// path: /post/[id|
|
||||
if i == len(path) {
|
||||
node.data = data
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user