Documentation
¶
Overview ¶
Package fields implements a simple field system, parsing and matching selectors with sets of fields.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fields ¶
type Fields interface {
// Has returns whether the provided field exists.
Has(field string) (exists bool)
// Get returns the value for the provided field.
Get(field string) (value string)
}
Fields allows you to present fields independently from their storage.
type Selector ¶
type Selector interface {
// Matches returns true if this selector matches the given set of fields.
Matches(Fields) bool
// Empty returns true if this selector does not restrict the selection space.
Empty() bool
// RequiresExactMatch allows a caller to introspect whether a given selector
// requires a single specific field to be set, and if so returns the value it
// requires.
RequiresExactMatch(field string) (value string, found bool)
// Transform returns a new copy of the selector after TransformFunc has been
// applied to the entire selector, or an error if fn returns an error.
Transform(fn TransformFunc) (Selector, error)
// String returns a human readable string that represents this selector.
String() string
}
Selector represents a field selector.
func OneTermEqualSelector ¶
func OneTermEqualSelector(k, v string) Selector
OneTermEqualSelector returns an object that matches objects where one field/field equals one value. Cannot return an error.
func ParseAndTransformSelector ¶
func ParseAndTransformSelector(selector string, fn TransformFunc) (Selector, error)
Parses the selector and runs them through the given TransformFunc.
func ParseSelector ¶
func ParseSelector(selector string) (Selector, error)
ParseSelector takes a string representing a selector and returns an object suitable for matching, or an error.
func ParseSelectorOrDie ¶ added in v1.2.0
func ParseSelectorOrDie(s string) Selector
ParseSelectorOrDie takes a string representing a selector and returns an object suitable for matching, or panic when an error occur.
func SelectorFromSet ¶
func SelectorFromSet(ls Set) Selector
SelectorFromSet returns a Selector which will match exactly the given Set. A nil Set is considered equivalent to Everything().
type Set ¶
type Set map[string]string
Set is a map of field:value. It implements Fields.
func (Set) AsSelector ¶
func (ls Set) AsSelector() Selector
AsSelector converts fields into a selectors.
func (Set) Get ¶
func (ls Set) Get(field string) string
Get returns the value in the map for the provided field.
type TransformFunc ¶
type TransformFunc func(field, value string) (newField, newValue string, err error)
Function to transform selectors.