Documentation ¶
Overview ¶
Package filters provides tools for encoding a mapping of keys to a set of multiple values.
Index ¶
- func ToJSON(a Args) (string, error)
- func ToParamWithVersion(version string, a Args) (string, error)deprecated
- type Args
- func (args Args) Add(key, value string)
- func (args Args) Clone() (newArgs Args)
- func (args Args) Contains(field string) bool
- func (args Args) Del(key, value string)
- func (args Args) ExactMatch(key, source string) bool
- func (args Args) FuzzyMatch(key, source string) bool
- func (args Args) Get(key string) []string
- func (args Args) GetBoolOrDefault(key string, defaultValue bool) (bool, error)
- func (args Args) Keys() []string
- func (args Args) Len() int
- func (args Args) MarshalJSON() ([]byte, error)
- func (args Args) Match(field, source string) bool
- func (args Args) MatchKVList(key string, sources map[string]string) bool
- func (args Args) UniqueExactMatch(key, source string) bool
- func (args Args) UnmarshalJSON(raw []byte) error
- func (args Args) Validate(accepted map[string]bool) error
- func (args Args) WalkValues(field string, op func(value string) error) error
- type KeyValuePair
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ToParamWithVersion
deprecated
ToParamWithVersion encodes Args as a JSON string. If version is less than 1.22 then the encoded format will use an older legacy format where the values are a list of strings, instead of a set.
Deprecated: do not use in any new code; use ToJSON instead
Types ¶
type Args ¶
type Args struct {
// contains filtered or unexported fields
}
Args stores a mapping of keys to a set of multiple values.
func NewArgs ¶
func NewArgs(initialArgs ...KeyValuePair) Args
NewArgs returns a new Args populated with the initial args
func (Args) ExactMatch ¶
ExactMatch returns true if the source matches exactly one of the values.
func (Args) FuzzyMatch ¶
FuzzyMatch returns true if the source matches exactly one value, or the source has one of the values as a prefix.
func (Args) GetBoolOrDefault ¶
GetBoolOrDefault returns a boolean value of the key if the key is present and is interpretable as a boolean value. Otherwise the default value is returned. Error is not nil only if the filter values are not valid boolean or are conflicting.
func (Args) MarshalJSON ¶
MarshalJSON returns a JSON byte representation of the Args
func (Args) MatchKVList ¶
MatchKVList returns true if all the pairs in sources exist as key=value pairs in the mapping at key, or if there are no values at key.
Example ¶
args := NewArgs( Arg("label", "image=foo"), Arg("label", "state=running")) // returns true because there are no values for bogus b := args.MatchKVList("bogus", nil) fmt.Println(b) // returns false because there are no sources b = args.MatchKVList("label", nil) fmt.Println(b) // returns true because all sources are matched b = args.MatchKVList("label", map[string]string{ "image": "foo", "state": "running", }) fmt.Println(b) // returns false because the values do not match b = args.MatchKVList("label", map[string]string{ "image": "other", }) fmt.Println(b)
Output: true false true false
func (Args) UniqueExactMatch ¶
UniqueExactMatch returns true if there is only one value and the source matches exactly the value.
func (Args) UnmarshalJSON ¶
UnmarshalJSON populates the Args from JSON encode bytes
type KeyValuePair ¶
KeyValuePair are used to initialize a new Args
func Arg ¶
func Arg(key, value string) KeyValuePair
Arg creates a new KeyValuePair for initializing Args