filter

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: GPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chain

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

Chain is a filter type that wraps other filter rules and itself. Therefore, it implements the Filter interface to allow it to be part of its ruleset. It supports also adding and popping filter rules individually.

func (*Chain) Eval

func (c *Chain) Eval(filterable Filterable) (bool, error)

Eval evaluates the filter rule sets recursively based on their operator type.

func (*Chain) ExtractConditions

func (c *Chain) ExtractConditions() []*Condition

type CompOperator

type CompOperator string

CompOperator is a type used for grouping the individual comparison operators of a filter string.

const (
	Equal            CompOperator = "="
	UnEqual          CompOperator = "!="
	Like             CompOperator = "~"
	UnLike           CompOperator = "!~"
	LessThan         CompOperator = "<"
	LessThanEqual    CompOperator = "<="
	GreaterThan      CompOperator = ">"
	GreaterThanEqual CompOperator = ">="
)

List of the supported comparison operators.

type Condition

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

Condition represents a single filter condition. It provides an implementation of the Filter interface for each of the supported CompOperator. All it's fields are read-only and aren't supposed to change at runtime. For read access, you can check the available exported methods.

func (*Condition) Column

func (c *Condition) Column() string

Column returns the column of this Condition.

func (*Condition) Eval

func (c *Condition) Eval(filterable Filterable) (bool, error)

Eval evaluates this Condition based on its operator. Returns true when the filter evaluates to true false otherwise.

func (*Condition) ExtractConditions

func (c *Condition) ExtractConditions() []*Condition

func (*Condition) Value

func (c *Condition) Value() string

Value returns the value of this Condition.

type Exists

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

func NewExists

func NewExists(column string) *Exists

func (*Exists) Eval

func (e *Exists) Eval(filterable Filterable) (bool, error)

func (*Exists) ExtractConditions

func (e *Exists) ExtractConditions() []*Condition

type Filter

type Filter interface {
	Eval(filterable Filterable) (bool, error)
	ExtractConditions() []*Condition
}

Filter is implemented by every filter chains and filter conditions.

func Parse

func Parse(expression string) (Filter, error)

Parse parses an object filter expression.

type Filterable

type Filterable interface {
	EvalEqual(key string, value string) (bool, error)
	EvalLess(key string, value string) (bool, error)
	EvalLike(key string, value string) (bool, error)
	EvalLessOrEqual(key string, value string) (bool, error)
	EvalExists(key string) bool
}

Filterable is implemented by every filterable type.

type LogicalOp

type LogicalOp string

LogicalOp is a type used for grouping the logical operators of a filter string.

const (
	// None represents a filter chain type that matches when none of its ruleset matches.
	None LogicalOp = "!"
	// All represents a filter chain type that matches when all of its ruleset matches.
	All LogicalOp = "&"
	// Any represents a filter chain type that matches when at least one of its ruleset matches.
	Any LogicalOp = "|"
)

type Parser

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

Jump to

Keyboard shortcuts

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