diff --git a/README.md b/README.md index 35db2f4..0fae7c4 100644 --- a/README.md +++ b/README.md @@ -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", "...") diff --git a/tree.go b/tree.go index cb017d8..652fc7f 100644 --- a/tree.go +++ b/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