filters

package
v0.0.0-...-7ef7dd6 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2018 License: Apache-2.0 Imports: 3 Imported by: 0

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 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 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) 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) UnmarshalJSON

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

UnmarshalJSON populates the Args from JSON encode bytes

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