Documentation ¶
Overview ¶
Package path contains methods for dealing with key.Paths.
Index ¶
- Variables
- func Append(path key.Path, elements ...interface{}) key.Path
- func Base(path key.Path) key.Key
- func Clone(path key.Path) key.Path
- func Equal(a, b key.Path) bool
- func FromString(str string) key.Path
- func HasElement(a key.Path, b key.Key) bool
- func HasPrefix(a, b key.Path) bool
- func Join(paths ...key.Path) key.Path
- func Match(a, b key.Path) bool
- func MatchPrefix(a, b key.Path) bool
- func New(elements ...interface{}) key.Path
- func Parent(path key.Path) key.Path
- type Map
- type MapOf
- func (m *MapOf[T]) Delete(p key.Path) bool
- func (m *MapOf[T]) Get(p key.Path) (T, bool)
- func (m *MapOf[T]) GetLongestPrefix(p key.Path) (key.Path, T, bool)
- func (m *MapOf[T]) IsEmpty() bool
- func (m *MapOf[T]) Set(p key.Path, v T) bool
- func (m *MapOf[T]) String() string
- func (m *MapOf[T]) Visit(p key.Path, fn func(v T) error) error
- func (m *MapOf[T]) VisitChildren(p key.Path, fn func(v T) error) error
- func (m *MapOf[T]) VisitPrefixed(p key.Path, fn func(v T) error) error
- func (m *MapOf[T]) VisitPrefixes(p key.Path, fn func(v T) error) error
- type VisitorFunc
- type WildcardType
Constants ¶
This section is empty.
Variables ¶
var Wildcard = key.New(WildcardType{})
Wildcard is a special element in a path that is used by Map and the Match* functions to match any other element.
Functions ¶
func Append ¶
Append appends a variable number of elements to a path. Each element may either be a key.Key or a value that can be wrapped by a key.Key. Note that calling Append on a single path returns that same path, whereas in all other cases a new path is returned.
func Equal ¶
Equal returns whether path a and path b are the same length and whether each element in b corresponds to the same element in a.
func FromString ¶
FromString constructs a path from the elements resulting from a split of the input string by "/". Strings that do not lead with a '/' are accepted but not reconstructable with key.Path.String. Both "" and "/" are treated as a key.Path{}.
func HasElement ¶
HasElement returns whether element b exists in path a.
func HasPrefix ¶
HasPrefix returns whether path b is a prefix of path a. It checks that b is at most the length of path a and whether each element in b corresponds to the same element in a from the first element.
func Join ¶
Join joins a variable number of paths together. Each path in the joining is treated as a subpath of its predecessor. Calling Join with no or only empty paths returns nil.
func Match ¶
Match returns whether path a and path b are the same length and whether each element in b corresponds to the same element or a wildcard in a.
func MatchPrefix ¶
MatchPrefix returns whether path b is a prefix of path a where path a may contain wildcards. It checks that b is at most the length of path a and whether each element in b corresponds to the same element or a wildcard in a from the first element.
Types ¶
type Map ¶
Map associates paths to values. It allows wildcards. A Map is primarily used to register handlers with paths that can be easily looked up each time a path is updated.
type MapOf ¶
type MapOf[T any] struct { // contains filtered or unexported fields }
MapOf associates paths to values of type T. It allows wildcards. A Map is primarily used to register handlers with paths that can be easily looked up each time a path is updated.
func (*MapOf[T]) Delete ¶
Delete unregisters the value registered with a path. It returns true if a value was deleted and false otherwise.
func (*MapOf[T]) Get ¶
Get returns the value registered with an exact match of a path p. If there is no exact match for p, Get returns the zero value and false. If p has an exact match and it is set to true, Get returns its value and true.
func (*MapOf[T]) GetLongestPrefix ¶
GetLongestPrefix determines the longest prefix of p for which an entry exists within the path map. If such a prefix exists, this function returns the prefix path, its associated value, and true. Otherwise, this functions returns the empty path, the zero value of T, and false.
func (*MapOf[T]) Set ¶
Set registers a path p with a value. If the path was already registered with a value it returns false and true otherwise.
func (*MapOf[T]) Visit ¶
Visit calls a function fn for every value in the Map that is registered with a match of a path p. In the general case, time complexity is linear with respect to the length of p but it can be as bad as O(2^len(p)) if there are a lot of paths with wildcards registered.
func (*MapOf[T]) VisitChildren ¶
VisitChildren calls fn for every child for every node that matches the provided path.
func (*MapOf[T]) VisitPrefixed ¶
VisitPrefixed calls fn for every value in the map that is registerd with a path that is prefixed by p. This method can be used to visit every registered path if p is the empty path (or root path) which prefixes all paths.
type VisitorFunc ¶
VisitorFunc is a function that handles the value associated with a path in a Map. Note that only the value is passed in as an argument since the path can be stored inside the value if needed.
type WildcardType ¶
type WildcardType struct{}
WildcardType is the type used to construct a Wildcard. It implements the value.Value interface so it can be used as a key.Key.
func (WildcardType) Equal ¶
func (w WildcardType) Equal(other interface{}) bool
Equal implements the key.Comparable interface.
func (WildcardType) MarshalJSON ¶
func (w WildcardType) MarshalJSON() ([]byte, error)
MarshalJSON implements the value.Value interface.
func (WildcardType) String ¶
func (w WildcardType) String() string
func (WildcardType) ToBuiltin ¶
func (w WildcardType) ToBuiltin() interface{}
ToBuiltin implements the value.Value interface.