labels

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2018 License: Apache-2.0 Imports: 9 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) 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)

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
}

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

NewRegexpMatcher 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 NewPrefixMatcher

func NewPrefixMatcher(name, prefix string) Matcher

NewPrefixMatcher returns new Matcher for label name matching prefix.

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 PrefixMatcher

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

PrefixMatcher implements Matcher for labels which values matches prefix.

func (*PrefixMatcher) Matches

func (m *PrefixMatcher) Matches(v string) bool

Matches implements Matcher interface.

func (*PrefixMatcher) Name

func (m *PrefixMatcher) Name() string

Name implements Matcher interface.

func (*PrefixMatcher) Prefix

func (m *PrefixMatcher) Prefix() string

Prefix returns matching prefix.

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