Documentation ¶
Overview ¶
Package pathmux implements a tree lookup for values associated to paths.
This package is a fork of https://github.com/dimfeld/httptreemux.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Matcher ¶
type Matcher interface { // Match should return true and the object to be returned by the lookup, when the argument value fulfils the // conditions defined by the custom logic in the matcher itself. If it returns false, it instructs the // lookup to continue with backtracking from the current tree position. Match(value interface{}) (bool, interface{}) }
Matcher objects, when using the LookupMatch function, can be used for additional checks and to override the default result in case of path matches. The argument passed to the Match function is the original value passed to the Tree.Add function.
type Tree ¶
type Tree node
Tree structure to store values associated to paths.
func (*Tree) Add ¶
Add a value to the tree associated with a path. Paths may contain wildcards. Wildcards can be of two types:
- simple wildcard: e.g. /some/:wildcard/path, where a wildcard is matched to a single name in the path.
- free wildcard: e.g. /some/path/*wildcard, where a wildcard at the end of a path matches anything.
func (*Tree) Lookup ¶
Lookup tries to find a value in the tree associated to a path. If the found path definition contains wildcards, the names and values of the wildcards are returned in the second argument.
func (*Tree) LookupMatcher ¶
LookupMatcher tries to find value in the tree associated to a path. If the found path definition contains wildcards, the names and values of the wildcards are returned in the second argument. When a value is found, the matcher is called to check if the value meets the conditions implemented by the custom matcher. If it returns true, then the lookup is done and the additional return value from the matcher is returned as the lookup result. If it returns false, the lookup continues with backtracking from the current tree position.