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 ¶
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
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 ¶
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
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
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 = "|" )