Documentation ¶
Index ¶
- type Expr
- type Labels
- type MatchCallback
- type MultiMatcher
- func (mm *MultiMatcher[Key, ResultCollection]) AddEntry(key Key, matchExpr Expr, mc MatchCallback[ResultCollection]) error
- func (mm *MultiMatcher[_, _]) Length() int
- func (mm *MultiMatcher[_, ResultCollection]) Match(labels Labels) ResultCollection
- func (mm *MultiMatcher[_, ResultCollection]) MatchWithResultCollection(labels Labels, resultCollection ResultCollection) ResultCollection
- func (mm *MultiMatcher[Key, _]) RemoveEntry(key Key) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Expr ¶
Expr represents an expression that returns a bool decision based on labels.
Note that even though this interface is public, it is recommended to use Exprs from this package, as multimatcher can optimize them better.
(we're not doing it right now, but in future we might want to perform some optimizations like common expression elimination or running all regexes in one go (e.g. with engine like hyperscan)).
func LabelEquals ¶
LabelEquals returns an expression that checks if the given label is exactly equal to the value.
func LabelExists ¶
LabelExists returns an expression that checks if the given label exists.
func LabelMatchesRegex ¶
LabelMatchesRegex compiles a regex and returns an expression that checks if the given label contains any match of the regex.
type MatchCallback ¶
type MatchCallback[ResultCollection any] func(ResultCollection) ResultCollection
MatchCallback is called on entry in case of successful match. It should modify result collection and return changed one (e.g. by appending some object).
func Appender ¶
func Appender[T any](value T) MatchCallback[[]T]
Appender can be used to create a simple MatchCallback in case the ResultCollection is []T.
type MultiMatcher ¶
type MultiMatcher[Key comparable, ResultCollection any] struct { // contains filtered or unexported fields }
MultiMatcher is a database of items (entries) and their corresponding LabelSelector. Provides APIs to Add/Remove entries, Match against labels.
Key is the type that identifies entries – used in adding / deleting, e.g. string. ResultCollection is a collection type that will be used in collecting results from Match, e.g. slice. Zero value of the ResultCollection should represent an empty one.
func New ¶
func New[Key comparable, ResultCollection any]() *MultiMatcher[Key, ResultCollection]
New returns a new multi matcher object.
func (*MultiMatcher[Key, ResultCollection]) AddEntry ¶
func (mm *MultiMatcher[Key, ResultCollection]) AddEntry(key Key, matchExpr Expr, mc MatchCallback[ResultCollection]) error
AddEntry adds an entry to the MultiMatcher.
Key is an arbitrary key to map this entry – should be unique, can be used to remove the entry. MatchCallback is a callback used by Match in case of successful match. The entry is considered matching if matchExpr.Evaluate(labels) returns true.
func (*MultiMatcher[_, _]) Length ¶
func (mm *MultiMatcher[_, _]) Length() int
Length returns number of entries in the MultiMatcher.
func (*MultiMatcher[_, ResultCollection]) Match ¶
func (mm *MultiMatcher[_, ResultCollection]) Match(labels Labels) ResultCollection
Match runs matching against labels and returns a collection of results.
Starting with empty ResultCollection, calls MatchCallback for every entry which matches given labels, and returns resulting ResultCollection.
func (*MultiMatcher[_, ResultCollection]) MatchWithResultCollection ¶
func (mm *MultiMatcher[_, ResultCollection]) MatchWithResultCollection(labels Labels, resultCollection ResultCollection) ResultCollection
MatchWithResultCollection runs matching against labels and returns a collection of results.
Starting with empty ResultCollection, calls MatchCallback for every entry which matches given labels, and returns resulting ResultCollection.
func (*MultiMatcher[Key, _]) RemoveEntry ¶
func (mm *MultiMatcher[Key, _]) RemoveEntry(key Key) error
RemoveEntry removes an entry in MultiMatcher at key.