filter

package
v0.0.0-...-614ca16 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OperatorKey      = ""
	OperatorEqual    = "=="
	OperatorNotEqual = "!="
	OperatorRegex    = "?="
)

Variables

View Source
var Operators = map[string]OperatorFactory{
	"==": func(key, value string) (Operator, error) {
		return func(v string) bool {
			return value == v
		}, nil
	},
	"!=": func(key, value string) (Operator, error) {
		return func(v string) bool {
			return value != v
		}, nil
	},
	"?=": func(key, value string) (operator Operator, e error) {
		re, err := regexp.Compile(value)
		if err != nil {
			return nil, errors.Errorf("bad regex in %s?=%s: %s", key, value, err)
		}
		return func(value string) bool {
			return re.MatchString(value)
		}, nil
	},
}

Functions

func Exclude

func Exclude(from interface{}, filters ...Filter) interface{}

func Include

func Include(from interface{}, filters ...Filter) interface{}

func MatchFilter

func MatchFilter(labels Labels, filter Filter) bool

Types

type Chain

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

func Try

func Try() Chain

func (Chain) Excluding

func (c Chain) Excluding(f ...Filter) Chain

func (Chain) From

func (c Chain) From(from interface{}) interface{}

From returns the filtered set, or an empty value of the same type as from if an expectation failed.

func (Chain) FromErr

func (c Chain) FromErr(from interface{}) (interface{}, error)

FromErr returns the filtered set, or an error if all steps failed expectations.

func (Chain) Including

func (c Chain) Including(f ...Filter) Chain

func (Chain) String

func (c Chain) String() string

func (Chain) Then

func (c Chain) Then() Chain

func (Chain) ToGet

func (c Chain) ToGet(min, max int) Chain

func (Chain) ToGetAtLeast

func (c Chain) ToGetAtLeast(want int) Chain

func (Chain) ToGetExactly

func (c Chain) ToGetExactly(want int) Chain

type Filter

type Filter interface {
	fmt.Stringer
	IsMatch(l Labels) bool
}

func FilterFromOperator

func FilterFromOperator(label, key string, operator Operator) Filter

FilterFromOperator creates a new filter with the given operator.

func FilterFunc

func FilterFunc(label string, fn func(l Labels) bool) Filter

func FilterMatchAll

func FilterMatchAll() Filter

func MustParse

func MustParse(parts ...string) Filter

MustParse is like Parse but panics if parse fails.

func Parse

func Parse(parts ...string) (Filter, error)

Parse returns a filter based on key, value, and operator Argument patterns: `"key"` - Will match if the key is found `"keyOPvalue"` - Where OP is one or more none-word characters, will check the value of key against the provided value using the operator `"key", "op", "value"` - Will check the value at key against the value using the operator

type LabelFunc

type LabelFunc func() string

func (LabelFunc) Value

func (l LabelFunc) Value() string

type LabelString

type LabelString string

func (LabelString) Value

func (l LabelString) Value() string

type LabelValue

type LabelValue interface {
	Value() string
}

type Labelled

type Labelled interface {
	GetLabels() Labels
}

type Labels

type Labels map[string]LabelValue

func LabelsFromMap

func LabelsFromMap(m map[string]string) Labels

func (Labels) GetLabels

func (l Labels) GetLabels() Labels

Labels implements Labelled.

func (Labels) MarshalYAML

func (l Labels) MarshalYAML() (interface{}, error)

func (*Labels) UnmarshalYAML

func (l *Labels) UnmarshalYAML(unmarshal func(interface{}) error) error

type MatchMapArgContainer

type MatchMapArgContainer interface {
	GetMatchMapArgs() MatchMapArgs
	WithMatchMapArgs(args MatchMapArgs) interface{}
}

type MatchMapArgs

type MatchMapArgs map[string]string

func (MatchMapArgs) String

func (e MatchMapArgs) String() string

type MatchMapConfig

type MatchMapConfig map[string]MatchMapConfigValues

func (MatchMapConfig) Matches

func (e MatchMapConfig) Matches(args MatchMapArgs) bool

type MatchMapConfigValue

type MatchMapConfigValue string

func (MatchMapConfigValue) Matches

func (m MatchMapConfigValue) Matches(arg string) bool

type MatchMapConfigValues

type MatchMapConfigValues []MatchMapConfigValue

func MatchMapConfigValuesFromStrings

func MatchMapConfigValuesFromStrings(ss []string) MatchMapConfigValues

type Operator

type Operator func(v string) bool

type OperatorFactory

type OperatorFactory func(key, value string) (Operator, error)

type SimpleFilter

type SimpleFilter struct {
	Raw      string
	Key      string
	Value    string
	Operator Operator
}

func (SimpleFilter) IsMatch

func (s SimpleFilter) IsMatch(l Labels) bool

func (SimpleFilter) String

func (s SimpleFilter) String() string

Jump to

Keyboard shortcuts

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