skipper: github.com/zalando/skipper/pathmux Index | Files

package pathmux

import "github.com/zalando/skipper/pathmux"

Package pathmux implements a tree lookup for values associated to paths.

This package is a fork of https://github.com/dimfeld/httptreemux.

Index

Package Files

tree.go viztree.go

type Matcher Uses

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 Uses

type Tree node

Tree structure to store values associated to paths.

func (*Tree) Add Uses

func (t *Tree) Add(path string, value interface{}) error

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 Uses

func (t *Tree) Lookup(path string) (interface{}, []string)

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 Uses

func (t *Tree) LookupMatcher(path string, m Matcher) (interface{}, []string, interface{})

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 Uses

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 Uses

func NewVizTree(tree *Tree) *VizTree

Creates a new visualization tree from a pathmux.Tree.

Package pathmux imports 3 packages (graph) and is imported by 5 packages. Updated 2019-11-06. Refresh now. Tools for package owners.