filters

package
v0.0.0-...-8680cc4 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: Apache-2.0 Imports: 4 Imported by: 39

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBadFormat = errors.New("bad format of filter (expected name=value)")

ErrBadFormat is an error returned when a filter is not in the form key=value

Functions

func FamiliarMatch

func FamiliarMatch(pattern string, ref string) (bool, error)

FamiliarMatch decide the ref match the pattern or not

func ToParam

func ToParam(a Args) (string, error)

ToParam packs the Args into a string for easy transport from client to server.

Types

type Args

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

Args stores filter arguments as map key:{map key: bool}. It contains an aggregation of the map of arguments (which are in the form of -f 'key=value') based on the key, and stores values for the same key in a map with string keys and boolean values. e.g given -f 'label=label1=1' -f 'label=label2=2' -f 'image.name=ubuntu' the args will be {"image.name":{"ubuntu":true},"label":{"label1=1":true,"label2=2":true}}

func FromFilterOpts

func FromFilterOpts(filter []string) (Args, error)

FromFilterOpts parse key=value to Args string from cli opts

func FromParam

func FromParam(p string) (Args, error)

FromParam 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 ParseFlag

func ParseFlag(arg string, prev Args) (Args, error)

ParseFlag parses a key=value string and adds it to an Args.

func (Args) Add

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

Add a new value to the set of values

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(field, source string) bool

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

func (Args) Get

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

Get returns the list of values associated with the key

func (Args) Len

func (args Args) Len() int

Len returns the number of fields in the arguments.

func (Args) MarshalJSON

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

MarshalJSON returns a JSON byte representation of the Args

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.

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.

type KeyValuePair

type KeyValuePair struct {
	Key   string
	Value string
}

KeyValuePair is 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