labels

package
v0.0.0-...-a69e935 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2019 License: Apache-2.0, MIT Imports: 4 Imported by: 22

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bag

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

Bag represents a bag of labels and their counts, i.e. it is a multi-bag.

func NewBag

func NewBag() *Bag

NewBag will create a new label bag.

func (*Bag) Add

func (bag *Bag) Add(labels ...*Label)

Add adds a label to this label bag with a count of 1.

func (*Bag) AddAll

func (bag *Bag) AddAll(other *Bag)

AddAll adds all labels in the given label bag to this label bag.

func (*Bag) Contains

func (bag *Bag) Contains(label *Label) bool

Contains returns true iff the count of the label is strictly higher than zero.

func (*Bag) Count

func (bag *Bag) Count(label *Label) int

Count counts the number of labels that this label matches.

func (*Bag) Find

func (bag *Bag) Find(label *Label) []*Label

Find will find all labels matching the given label.

func (*Bag) Labels

func (bag *Bag) Labels() []*Label

Labels returns a new slice of all the labels in the bag.

func (*Bag) Set

func (bag *Bag) Set(label *Label, count int)

Set adds the value in the label bag and sets it count.

func (*Bag) SetAll

func (bag *Bag) SetAll(other *Bag)

SetAll sets all labels in the given label bag to the labels and counts in the other label bag, any labels that exists in the label bag but not in other will still be present with the same count.

func (*Bag) Size

func (bag *Bag) Size() int

Size will return the number of different labels in the label bag.

type Label

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

Label represents an immutable label which consists of a list of names. Since a label is a list of names the label have a hierarchy, e.g. the labels foo.bar and foo.baz can be thought of as being nested under the label foo.*.

func NewLabel

func NewLabel(names ...string) *Label

NewLabel creates a new label from the given names.

func (*Label) Match

func (label *Label) Match(other *Label) bool

Match returns true iff the label matches the other label or vice versa taking wildcards into account. When matching one label to another label then a wildcard will match any name in the other label at the same position.

func (*Label) Names

func (label *Label) Names() []string

Names returns a copy of the names in the label.

func (*Label) String

func (label *Label) String() string

String returns a concatenation of the names in the label with dot as a separator.

func (*Label) Wildcard

func (label *Label) Wildcard() bool

Wildcard returns true iff the label contains a wildcard.

type Template

type Template interface {
	// Bind will bind the template with the given name to the given value.
	Bind(name, value string) Template

	// Mappings will return a map of all the current variables and their values.
	Mappings() map[string]string

	// Instantiate will create a new label where all templates have been replaced with their currently bound value.
	Instantiate() *Label
}

Template represents a label template which can be instantiated with different values. A template can create labels like schemaless.cluster.percona-cluster-$instance-name$-$zone$-db$cluster$ where the labelTemplate substrings <instance-name>, <zone> and <cluster> can then be bound later, and re-bound to instantiate different labels.

func NewTemplate

func NewTemplate(names ...string) Template

NewTemplate will create a new label template which can be used to create labels with. Each name in the slice of supplied names can use template substrings like percona-cluster-$instance-name$-$zone$-db$cluster$ and then later bind the template names <instance-name>, <zone> and <cluster> using the bind method.

type TemplateSet

type TemplateSet interface {
	// Bind will bind the variable with the given name to the given value.
	Bind(name, value string) TemplateSet

	// Add will add a label template whose variables will be set by this variable set.
	Add(template Template) TemplateSet

	// AddAll adds all label templates from the given template set to this template set.
	AddAll(set TemplateSet) TemplateSet

	// Templates returns all templates of the template set.
	Templates() []Template

	// Mappings will return a map of all the current variables and their values.
	Mappings() map[string]string
}

TemplateSet represents a set of label templates where the variables of all templates can be bound for all label templates.

func NewTemplateSet

func NewTemplateSet() TemplateSet

NewTemplateSet will create a new template set where templates can be added and variables can be bound for all templates at the same time.

Jump to

Keyboard shortcuts

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