Documentation ¶
Overview ¶
A simple radix like tree specialized for URL path routing with supports for wildcards.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Radix ¶
type Radix[P any] struct { // contains filtered or unexported fields }
func (*Radix[P]) Add ¶
Add an uri path template and the corresponding payload. Path component must be separated by '/'. Wildcards path component use a ':' prefix. Examples:
radix := New[string]() radix.Add("/users", "List users") radix.Add("/users/:id", "Get a user by id") radix.Add("/users/self", "Get the current user") radix.Add("/users/:user_id/pets/", "...") radix.Add("/users/:user_id/pets/:pet_id", "...") radix.Add("/users/:user_id/friends/:friend_id", "...") radix.Add("/users/:user_id/friends/", "...")
func (*Radix[P]) Search ¶
Search the radix tree with a given path. It returns all the match found. If there are no match, return an empty slice. When a path component match multiple fixeds or wildcards registered paths, all paths are returned bu the fixed paths appear first, then the wildcard path. Example:
radix.Search("/users/toto") // => [{"Get a user by id", [id:toto]}}] radix.Search("/users/self") // => [{"Get the current user", []}, {"Get a user by id", [id:self]}}] radix.Search("/test") // => empty radix.Search("nowhere") // => empty radix.Search("") // => empty
Click to show internal directories.
Click to hide internal directories.