filters

package
v0.0.0-...-44a430f Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2021 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package filters provides tools for encoding a mapping of keys to a set of multiple values.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ToJSON

func ToJSON(a Args) (string, error)

ToJSON returns the Args as a JSON encoded string

func ToParamWithVersion deprecated

func ToParamWithVersion(version string, a Args) (string, error)

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 FromJSON

func FromJSON(p string) (Args, error)

FromJSON decodes a JSON encoded string into Args

func NewArgs

func NewArgs(initialArgs ...KeyValuePair) Args

NewArgs returns a new Args populated with the initial args

func (Args) Add

func (args Args) Add(key, value string)

Add a new value to the set of values

func (Args) Clone

func (args Args) Clone() (newArgs Args)

Clone returns a copy of args.

func (Args) Contains

func (args Args) Contains(field string) bool

Contains returns true if the key exists in the mapping

func (Args) Del

func (args Args) Del(key, value string)

Del removes a value from the set

func (Args) ExactMatch

func (args Args) ExactMatch(key, source string) bool

ExactMatch returns true if the source matches exactly one of the values.

func (Args) FuzzyMatch

func (args Args) FuzzyMatch(key, source string) bool

FuzzyMatch returns true if the source matches exactly one value, or the source has one of the values as a prefix.

func (Args) Get

func (args Args) Get(key string) []string

Get returns the list of values associated with the key

func (Args) Keys

func (args Args) Keys() []string

Keys returns all the keys in list of Args

func (Args) Len

func (args Args) Len() int

Len returns the number of keys in the mapping

func (Args) MarshalJSON

func (args Args) MarshalJSON() ([]byte, error)

MarshalJSON returns a JSON byte representation of the Args

func (Args) Match

func (args Args) Match(field, source string) bool

Match returns true if any of the values at key match the source string

func (Args) MatchKVList

func (args Args) MatchKVList(key string, sources map[string]string) bool

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
args.MatchKVList("bogus", nil)

// returns false because there are no sources
args.MatchKVList("label", nil)

// returns true because all sources are matched
args.MatchKVList("label", map[string]string{
	"image": "foo",
	"state": "running",
})

// returns false because the values do not match
args.MatchKVList("label", map[string]string{
	"image": "other",
})
Output:

func (Args) UniqueExactMatch

func (args Args) UniqueExactMatch(key, source string) bool

UniqueExactMatch returns true if there is only one value and the source matches exactly the value.

func (Args) UnmarshalJSON

func (args Args) UnmarshalJSON(raw []byte) error

UnmarshalJSON populates the Args from JSON encode bytes

func (Args) Validate

func (args Args) Validate(accepted map[string]bool) error

Validate compared the set of accepted keys against the keys in the mapping. An error is returned if any mapping keys are not in the accepted set.

func (Args) WalkValues

func (args Args) WalkValues(field string, op func(value string) error) error

WalkValues iterates over the list of values for a key in the mapping and calls op() for each value. If op returns an error the iteration stops and the error is returned.

type KeyValuePair

type KeyValuePair struct {
	Key   string
	Value string
}

KeyValuePair are used to initialize a new Args

func Arg

func Arg(key, value string) KeyValuePair

Arg creates a new KeyValuePair for initializing Args

Jump to

Keyboard shortcuts

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