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 LookupMatcher 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 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 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.
type VizTree ¶ added in v0.9.119
type VizTree struct { Path string // string representation of the node path Children []*VizTree // children nodes of the current node CanMatch bool // flag that is set to true if the node has a matcher }
Exploded version of the pathmux tree designed for being easy to use in a visualization. Simple wildcard nodes are represented by the ':' prefix and free wildcard nodes with the '*' prefix.
func NewVizTree ¶ added in v0.9.119
Creates a new visualization tree from a pathmux.Tree.