labels

package
v2.13.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 8, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compare

func Compare(a, b Labels) int

Compare compares the two label sets. The result will be 0 if a==b, <0 if a < b, and >0 if a > b.

Types

type EqualMatcher

type EqualMatcher struct {
	// contains filtered or unexported fields
}

EqualMatcher matches on equality.

func (EqualMatcher) Matches

func (m EqualMatcher) Matches(v string) bool

Matches implements Matcher interface.

func (EqualMatcher) Name

func (m EqualMatcher) Name() string

Name implements Matcher interface.

func (EqualMatcher) String

func (m EqualMatcher) String() string

String implements Matcher interface.

func (EqualMatcher) Value

func (m EqualMatcher) Value() string

Value returns the matched value.

type Label

type Label struct {
	Name, Value string
}

Label is a key/value pair of strings.

type Labels

type Labels []Label

Labels is a sorted set of labels. Order has to be guaranteed upon instantiation.

func FromMap

func FromMap(m map[string]string) Labels

FromMap returns new sorted Labels from the given map.

func FromStrings

func FromStrings(ss ...string) Labels

FromStrings creates new labels from pairs of strings.

func New

func New(ls ...Label) Labels

New returns a sorted Labels from the given labels. The caller has to guarantee that all label names are unique.

func ReadLabels

func ReadLabels(fn string, n int) ([]Labels, error)

ReadLabels reads up to n label sets in a JSON formatted file fn. It is mostly useful to load testing data.

func (Labels) Equals

func (ls Labels) Equals(o Labels) bool

Equals returns whether the two label sets are equal.

func (Labels) Get

func (ls Labels) Get(name string) string

Get returns the value for the label with the given name. Returns an empty string if the label doesn't exist.

func (Labels) Hash

func (ls Labels) Hash() uint64

Hash returns a hash value for the label set.

func (Labels) Len

func (ls Labels) Len() int

func (Labels) Less

func (ls Labels) Less(i, j int) bool

func (Labels) Map

func (ls Labels) Map() map[string]string

Map returns a string map of the labels.

func (Labels) String

func (ls Labels) String() string

func (Labels) Swap

func (ls Labels) Swap(i, j int)

func (Labels) WithoutEmpty

func (ls Labels) WithoutEmpty() Labels

WithoutEmpty returns the labelset without empty labels. May return the same labelset.

type Matcher

type Matcher interface {
	// Name returns the label name the matcher should apply to.
	Name() string
	// Matches checks whether a value fulfills the constraints.
	Matches(v string) bool
	// String returns a human readable matcher.
	String() string
}

Matcher specifies a constraint for the value of a label.

func NewEqualMatcher

func NewEqualMatcher(name, value string) Matcher

NewEqualMatcher returns a new matcher matching an exact label value.

func NewMustRegexpMatcher

func NewMustRegexpMatcher(name, pattern string) Matcher

NewMustRegexpMatcher returns a new matcher verifying that a value matches the regular expression pattern. Will panic if the pattern is not a valid regular expression.

func NewRegexpMatcher

func NewRegexpMatcher(name, pattern string) (Matcher, error)

NewRegexpMatcher returns a new matcher verifying that a value matches the regular expression pattern.

func Not

func Not(m Matcher) Matcher

Not inverts the matcher's matching result.

type NotMatcher

type NotMatcher struct {
	Matcher
}

NotMatcher inverts the matching result for a matcher.

func (NotMatcher) Matches

func (m NotMatcher) Matches(v string) bool

func (NotMatcher) String

func (m NotMatcher) String() string

type RegexpMatcher

type RegexpMatcher struct {
	// contains filtered or unexported fields
}

func (RegexpMatcher) Matches

func (m RegexpMatcher) Matches(v string) bool

func (RegexpMatcher) Name

func (m RegexpMatcher) Name() string

func (RegexpMatcher) String

func (m RegexpMatcher) String() string

func (RegexpMatcher) Value

func (m RegexpMatcher) Value() string

type Selector

type Selector []Matcher

Selector holds constraints for matching against a label set.

func (Selector) Matches

func (s Selector) Matches(labels Labels) bool

Matches returns whether the labels satisfy all matchers.

type Slice

type Slice []Labels

Slice is a sortable slice of label sets.

func (Slice) Len

func (s Slice) Len() int

func (Slice) Less

func (s Slice) Less(i, j int) bool

func (Slice) Swap

func (s Slice) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL