matcher

package
v0.0.0-...-8b28c38 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllCut

type AllCut[T any] struct{}

AllCut is a matcher that matches nothing. This is useful for applications like authorization, where a user/group/role may be disallowed from viewing data entirely.

func (*AllCut[T]) Matches

func (ac *AllCut[T]) Matches(T) bool

Matches is the canonical in-Go function for determining if T matches a specific implementation's rules.

func (*AllCut[T]) String

func (ac *AllCut[T]) String() string

String returns the string representation of the matcher instance

type AllPass

type AllPass[T any] struct{}

AllPass is a filter that matches everything and is the same as no filter. It is implemented here as a guard against universal operations occurring in the absence of filters.

func (*AllPass[T]) Matches

func (n *AllPass[T]) Matches(T) bool

Matches is the canonical in-Go function for determining if T matches a specific implementation's rules.

func (*AllPass[T]) String

func (n *AllPass[T]) String() string

type And

type And[T any] struct {
	Matchers []Matcher[T]
}

And is a set of filters that should be evaluated as a logical AND.

func (*And[T]) Add

func (a *And[T]) Add(m Matcher[T])

func (*And[T]) Matches

func (a *And[T]) Matches(that T) bool

Matches is the canonical in-Go function for determining if T matches a AND match rules.

func (*And[T]) String

func (a *And[T]) String() string

type FieldMapper

type FieldMapper[T any, U any] func(T, ast.Identifier) (U, error)

FieldMapper is the adapter which can fetch actual T instance data of type U leveraging the ast.Identifier definition.

type MapFieldMapper

type MapFieldMapper[T any] FieldMapper[T, map[string]string]

SliceFieldMapper is the adapter which can fetch actual T instance data of type map[string]string leveraging the ast.Identifier definition.

type MatchCompiler

type MatchCompiler[T any] struct {
	// contains filtered or unexported fields
}

MatchCompiler compiles an `ast.FilterNode` into a Matcher[T] implementation.

func NewMatchCompiler

func NewMatchCompiler[T any](
	stringFieldMapper StringFieldMapper[T],
	sliceFieldMapper SliceFieldMapper[T],
	mapFieldMapper MapFieldMapper[T],
	passes ...transform.CompilerPass,
) *MatchCompiler[T]

NewMatchCompiler creates a new MatchCompiler for T instances provided the funcs which can map ast.Identifier instances to a specific T field

func (*MatchCompiler[T]) Compile

func (mc *MatchCompiler[T]) Compile(filter ast.FilterNode) (Matcher[T], error)

Compile accepts an `ast.FilterNode` tree and compiles it into a `Matcher[T]` implementation which can be used to match T instances dynamically.

type Matcher

type Matcher[T any] interface {
	String() string

	// Matches is the canonical in-Go function for determining if T
	// matches a specific implementation's rules.
	Matches(T) bool
}

Matcher represents anything that can be used to match against given generic type T.

type MatcherGroup

type MatcherGroup[T any] interface {
	Matcher[T]

	Add(Matcher[T])
}

MatcherGroup is useful for dynamically creating group based matchers.

type Not

type Not[T any] struct {
	Matcher Matcher[T]
}

Not negates any filter contained within it

func (*Not[T]) Add

func (n *Not[T]) Add(m Matcher[T])

func (*Not[T]) Matches

func (n *Not[T]) Matches(that T) bool

Matches inverts the result of the child matcher

func (*Not[T]) String

func (n *Not[T]) String() string

type Or

type Or[T any] struct {
	Matchers []Matcher[T]
}

Or is a set of filters that should be evaluated as a logical OR.

func (*Or[T]) Add

func (o *Or[T]) Add(m Matcher[T])

func (*Or[T]) Matches

func (o *Or[T]) Matches(that T) bool

Matches is the canonical in-Go function for determining if T matches OR match rules.

func (*Or[T]) String

func (o *Or[T]) String() string

type SliceFieldMapper

type SliceFieldMapper[T any] FieldMapper[T, []string]

SliceFieldMapper is the adapter which can fetch actual T instance data of type []string leveraging the ast.Identifier definition.

type StringFieldMapper

type StringFieldMapper[T any] FieldMapper[T, string]

StringFieldMapper is the adapter which can fetch actual T instance data of type string leveraging the ast.Identifier definition.

type StringMapMatcher

type StringMapMatcher[T any] struct {
	Op         ast.FilterOp
	Identifier ast.Identifier
	Key        string
	// contains filtered or unexported fields
}

// StringMapMatcher matches properties of a T instance which are map[string]string

func (*StringMapMatcher[T]) Matches

func (smm *StringMapMatcher[T]) Matches(that T) bool

func (*StringMapMatcher[T]) String

func (smm *StringMapMatcher[T]) String() string

type StringMapMatcherFactory

type StringMapMatcherFactory[T any] struct {
	// contains filtered or unexported fields
}

StringMapMatcherFactory leverages a single MapFieldMapper[T] to generate instances of StringMapMatcher[T].

func NewStringMapMatcherFactory

func NewStringMapMatcherFactory[T any](fieldMapper MapFieldMapper[T]) *StringMapMatcherFactory[T]

NewStringMapMatcherFactory creates a new StringMapMatcher factory for a given T type.

func (*StringMapMatcherFactory[T]) NewStringMapMatcher

func (smmf *StringMapMatcherFactory[T]) NewStringMapMatcher(op ast.FilterOp, ident ast.Identifier, key string) *StringMapMatcher[T]

NewStringMapMatcher creates a new StringMapMatcher using the provided op, field ident and key for comparison

type StringMatcher

type StringMatcher[T any] struct {
	Op         ast.FilterOp
	Identifier ast.Identifier
	Value      string
	// contains filtered or unexported fields
}

StringMatcher matches properties of a T instance which are string.

func (*StringMatcher[T]) Matches

func (sm *StringMatcher[T]) Matches(that T) bool

Matches is the canonical in-Go function for determining if T matches string property comparison rules.

func (*StringMatcher[T]) String

func (sm *StringMatcher[T]) String() string

type StringMatcherFactory

type StringMatcherFactory[T any] struct {
	// contains filtered or unexported fields
}

StringMatcherFactory leverages a single StringFieldMapper[T] to generate instances of StringMatcher[T].

func NewStringMatcherFactory

func NewStringMatcherFactory[T any](fieldMapper StringFieldMapper[T]) *StringMatcherFactory[T]

NewStringMatcherFactory creates a new StringMatcher factory for a given T type.

func (*StringMatcherFactory[T]) NewStringMatcher

func (smf *StringMatcherFactory[T]) NewStringMatcher(op ast.FilterOp, ident ast.Identifier, value string) *StringMatcher[T]

NewStringMatcher creates a new StringMatcher using the provided op, field ident, and value comparison.

type StringSliceMatcher

type StringSliceMatcher[T any] struct {
	Op         ast.FilterOp
	Identifier ast.Identifier
	Value      string
	// contains filtered or unexported fields
}

StringSliceProperty is the lowest-level type of filter. It represents a filter operation (equality, inequality, etc.) on a property that contains a string slice

func (*StringSliceMatcher[T]) Matches

func (ssp *StringSliceMatcher[T]) Matches(that T) bool

func (*StringSliceMatcher[T]) String

func (ssp *StringSliceMatcher[T]) String() string

type StringSliceMatcherFactory

type StringSliceMatcherFactory[T any] struct {
	// contains filtered or unexported fields
}

StringMatcherFactory leverages a single StringSliceFieldMapper[T] to generate instances of StringSliceMatcher[T].

func NewStringSliceMatcherFactory

func NewStringSliceMatcherFactory[T any](fieldMapper SliceFieldMapper[T]) *StringSliceMatcherFactory[T]

NewStringSliceMatcherFactory creates a new StringMatcher factory for a given T type.

func (*StringSliceMatcherFactory[T]) NewStringSliceMatcher

func (smf *StringSliceMatcherFactory[T]) NewStringSliceMatcher(op ast.FilterOp, ident ast.Identifier, value string) *StringSliceMatcher[T]

NewStringMatcher creates a new StringSliceMatcher using the provided op, field ident, and value comparison.

Jump to

Keyboard shortcuts

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