filters

package
v0.0.0-...-d9d993d Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnknownComparator comparator = ""
	// norm(a) == norm(b)
	EqualTo = "EQ"
	// a === b
	StrictEqualTo = "StrictEQ"
	// a > b
	GreaterThan = "GT"
	// a < b
	LessThan = "LT"
	// "foo,bar,baz" contains "foo"
	TargetContains = "Cont"
	// "foo" is found in "foo,bar,baz"
	TargetIn = "IN"
	// always passes
	Passes = "Pass"
	// always fails
	Fails = "Fail"
	// passthrough for the target
	IdentityValue = "Identity"
	// "foo" is a prefix of "foobarbaz"
	TargetPrefixes = "Pfx"
	// "baz" is a suffix of "foobarbaz"
	TargetSuffixes = "Sfx"
	// "foo" equals any complete element prefix of "foo/bar/baz"
	TargetPathPrefix = "PathPfx"
	// "foo" equals any complete element in "foo/bar/baz"
	TargetPathContains = "PathCont"
	// "baz" equals any complete element suffix of "foo/bar/baz"
	TargetPathSuffix = "PathSfx"
	// "foo/bar/baz" equals the complete path "foo/bar/baz"
	TargetPathEquals = "PathEQ"
)

Variables

This section is empty.

Functions

func Must

func Must(input string, filters ...Filter) bool

Must returns true if ALL provided filters match the input. Returns false if no filters are provided

Types

type Filter

type Filter struct {
	Comparator        comparator `json:"comparator_type"`   // the type of comparison
	Targets           []string   `json:"targets"`           // the set of values to compare
	NormalizedTargets []string   `json:"normalizedTargets"` // the set of comparable values post normalization
	Negate            bool       `json:"negate"`            // when true, negate the comparator result

	// only used when the filter's purpose is to hold a value without intent for comparison
	Identity string `json:"identity"`

	// deprecated, kept around for deserialization
	Target        string `json:"target"` // the value to compare against
	ComparatorInt int    `json:"comparator"`
}

Filter contains a comparator func and the target to compare values against. Filter.Matches(v) returns true if Filter.Comparer(filter.target, v) is true.

func Contains

func Contains(targets []string) Filter

Contains creates a filter f where f.Compare(v) is true if, for any target t in f, t.Contains(v)

func Equal

func Equal(targets []string) Filter

Equal creates a filter f where f.Compare(v) is true if, for any target t in f, t == v

func Fail

func Fail() Filter

Fail creates a filter f where f.Compare(v) always returns false

func Greater

func Greater(targets []string) Filter

Greater creates a filter f where f.Compare(v) is true if, for any target t in f, t > v

func Identity

func Identity(id string) Filter

Identity creates a filter intended to hold values, rather than compare them. Comparatively, it'll behave the same as Equals.

func In

func In(targets []string) Filter

In creates a filter f where f.Compare(v) is true if, for any target t in f, v.Contains(t)

func Less

func Less(targets []string) Filter

Less creates a filter f where f.Compare(v) is true if, for any target t in f, t < v

func NotContains

func NotContains(targets []string) Filter

NotContains creates a filter f where f.Compare(v) is true if, for any target t in f, !t.Contains(v)

func NotEqual

func NotEqual(targets []string) Filter

NotEqual creates a filter f where f.Compare(v) is true if, for any target t in f, t != v

func NotGreater

func NotGreater(targets []string) Filter

NotGreater creates a filter f where f.Compare(v) is true if, for any target t in f, t <= v

func NotIn

func NotIn(targets []string) Filter

NotIn creates a filter f where f.Compare(v) is true if, for any target t in f, !v.Contains(t)

func NotLess

func NotLess(targets []string) Filter

NotLess creates a filter f where f.Compare(v) is true if, for any target t in f, t >= v

func NotPathContains

func NotPathContains(targets []string) Filter

NotPathContains creates a filter f where f.Compare(v) is true if, for any target t in f, for _every_ elem e in split(v), !t.Equals(e) || for _every_ sequence of elems in split(v), !t.Equals(path.Join(e[n:m])) ex: t="foo" returns false for v="/baz/foo/bar", but true for v="/baz/foobar" ex: t="baz/foo" returns false for v="/baz/foo/bar", but true for v="/baz/foobar"

func NotPathEquals

func NotPathEquals(targets []string) Filter

NotPathEquals creates a filter f where f.Compare(v) is true if, for any target t in f, !t.Equals(v) || !split(t)[i].Equals(split(v)[i]) for _all_ i in 0..len(t)-1 ex: t="foo" returns true v="/foo/bar", v="bar/foo/", and v="/foobar/" but false for for v="/foo/", v="/foo", and v="foo/"

func NotPathPrefix

func NotPathPrefix(targets []string) Filter

NotPathPrefix creates a filter f where f.Compare(v) is true if, for any target t in f, !t.Prefix(v) || !split(t)[i].Equals(split(v)[i]) for _any_ i in 0..len(t)-1 ex: t="/foo/bar" returns false for v="/foo/bar/baz", but true for v="/foo/barbaz"

func NotPathSuffix

func NotPathSuffix(targets []string) Filter

NotPathSuffix creates a filter f where f.Compare(v) is true if, for any target t in f, !t.Suffix(v) || !split(t)[i].Equals(split(v)[i]) for _any_ i in 0..len(t)-1 ex: t="/bar/baz" returns false for v="/foo/bar/baz", but true for v="/foobar/baz"

func NotPrefix

func NotPrefix(targets []string) Filter

NotPrefix creates a filter f where f.Compare(v) is true if, for any target t in f, !t.Prefix(v)

func NotStrictEqual

func NotStrictEqual(targets []string) Filter

NotStrictEqual creates a filter f where f.Compare(v) is true if, for any target t in f, t !== v. t and v are not normalized for this comparison. The comparison is case sensitive and ignores character folding.

func NotSuffix

func NotSuffix(targets []string) Filter

NotSuffix creates a filter f where f.Compare(v) is true if, for any target t in f, !t.Suffix(v)

func Pass

func Pass() Filter

Pass creates a filter f where f.Compare(v) always returns true

func PathContains

func PathContains(targets []string) Filter

PathContains creates a filter f where f.Compare(v) is true if, for any target t in f, for _any_ elem e in split(v), t.Equals(e) || for _any_ sequence of elems in split(v), t.Equals(path.Join(e[n:m])) ex: t="foo" returns true for v="/baz/foo/bar", but false for v="/baz/foobar" ex: t="baz/foo" returns true for v="/baz/foo/bar", but false for v="/baz/foobar"

func PathEquals

func PathEquals(targets []string) Filter

PathEquals creates a filter f where f.Compare(v) is true if, for any target t in f, t.Equals(v) && split(t)[i].Equals(split(v)[i]) for _all_ i in 0..len(t)-1 ex: t="foo" returns true for v="/foo/", v="/foo", and v="foo/" but false for v="/foo/bar", v="bar/foo/", and v="/foobar/"

func PathPrefix

func PathPrefix(targets []string) Filter

PathPrefix creates a filter f where f.Compare(v) is true if, for any target t in f, t.Prefix(v) && split(t)[i].Equals(split(v)[i]) for _all_ i in 0..len(t)-1 ex: t="/foo/bar" returns true for v="/foo/bar/baz", but false for v="/foo/barbaz"

func PathSuffix

func PathSuffix(targets []string) Filter

PathSuffix creates a filter f where f.Compare(v) is true if, for any target t in f, t.Suffix(v) && split(t)[i].Equals(split(v)[i]) for _all_ i in 0..len(t)-1 ex: t="/bar/baz" returns true for v="/foo/bar/baz", but false for v="/foobar/baz"

func Prefix

func Prefix(targets []string) Filter

Prefix creates a filter f where f.Compare(v) is true if, for any target t in f, t.Prefix(v)

func StrictEqual

func StrictEqual(targets []string) Filter

StrictEqual creates a filter f where f.Compare(v) is true if, for any target t in f, t === v. t and v are not normalized for this comparison. The comparison is case sensitive and ignores character folding.

func Suffix

func Suffix(targets []string) Filter

Suffix creates a filter f where f.Compare(v) is true if, for any target t in f, t.Suffix(v)

func (Filter) Compare

func (f Filter) Compare(input string) bool

Compare checks whether the input passes the filter.

func (Filter) CompareAny

func (f Filter) CompareAny(inputs ...string) bool

CompareAny checks whether any one of all the provided inputs passes the filter.

Note that, as a gotcha, CompareAny can resolve truthily for both the standard and negated versions of a filter. Ex: consider the input CompareAny(true, false), which will return true for both Equals(true) and NotEquals(true), because at least one element matches for both filters.

func (Filter) Conceal

func (f Filter) Conceal() string

func (Filter) Format

func (f Filter) Format(fs fmt.State, _ rune)

func (Filter) PlainString

func (f Filter) PlainString() string

func (Filter) String

func (f Filter) String() string

Jump to

Keyboard shortcuts

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