Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Engine ¶ added in v1.1.1200
type Engine interface { // Eval evaluates an expression given a set of variables and returns a generic type. Eval(ctx context.Context, expr string, vars map[string]interface{}) (interface{}, error) // GetVariables returns a list of variables mentioned in an expression GetVariables(ctx context.Context, expr string) ([]Variable, error) }
Engine represents an expression engine implementation.
type ExprEngine ¶ added in v1.1.1200
type ExprEngine struct { }
ExprEngine is an implementation of the expr-lang an expression engine.
func (*ExprEngine) Eval ¶ added in v1.1.1200
func (e *ExprEngine) Eval(ctx context.Context, exp string, vars map[string]interface{}) (interface{}, error)
Eval takes a context, an expression string, and a map of variables. It returns the result of the expression evaluation as an interface{} and any error encountered during the evaluation process. If the expression string is empty, it returns nil, nil. If the expression string starts with "=", the "=" character is removed from the expression. It then compiles the expression using expr.Compile() and returns any compilation error wrapped with an ErrWorkflowFatal error. It runs the compiled expression using expr.Run(), passing in the variables map, and returns the result and any evaluation error. If there is an evaluation error, it returns the error wrapped with an additional message. If the evaluation is successful, it returns the result and nil as the error.
func (*ExprEngine) GetVariables ¶ added in v1.1.1200
GetVariables takes a context and an expression string. It trims any leading and trailing white spaces from the expression string. If the expression string is empty, it returns nil, nil. If the expression string starts with "=", the "=" character is removed from the expression. It then parses the expression using parser.Parse() and returns any parse error. It walks through the AST of the parsed expression and collects all IdentifierNode types into a slice of Variable structs. Finally, it returns the collected variables and nil as the error.