filter

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: GPL-2.0 Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func (*Chain) String added in v1.0.0

func (c *Chain) String() string

String returns a string representation of this Chain for debugging purposes.

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) Attributes added in v1.0.0

func (c *Condition) Attributes() []string

Attributes returns the list of attributes this condition refers to.

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) String added in v1.0.0

func (c *Condition) String() string

String returns a string representation of this Condition for debugging purposes.

func (*Condition) Value

func (c *Condition) Value() any

Value returns the value of this Condition.

type Filter

type Filter interface {
	fmt.Stringer

	Eval(filterable Filterable) (bool, error)
	ExtractConditions() []*Condition
}

Filter is implemented by every filter chains and filter conditions.

func ParseASTExpr added in v1.0.0

func ParseASTExpr(expr string) (Filter, error)

ParseASTExpr parses a filter expression stored as a JSON object with an `ast` field, i.e. `{"ast": <filter JSON>}`, as produced for the rule object filter and escalation condition columns.

Returns an error if expr isn't valid JSON or doesn't contain the required `ast` field.

func UnmarshalJSON added in v1.0.0

func UnmarshalJSON(data []byte) (Filter, error)

UnmarshalJSON is a helper function to unmarshal a JSON representation of a filter into a Filter interface.

It recursively parses the JSON data to deduce the filter type (Chain or Condition) based on the `op` field and constructs the appropriate filter structure.

Returns nil if JSON null value is provided, and an error if the JSON is invalid or if required fields are missing.

type Filterable

type Filterable interface {
	EvalEqual(key []string, value any) (bool, error)
	EvalLess(key []string, value any) (bool, error)
	EvalLike(key []string, value any) (bool, error)
	EvalLessOrEqual(key []string, value any) (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 = "|"
)

Jump to

Keyboard shortcuts

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