Documentation
¶
Overview ¶
stepfunction stepfunction style expression evaluator
Index ¶
- Variables
- func IsBool(i any) bool
- func IsNull(i any) bool
- func IsNumeric(i any) bool
- func IsString(i any) bool
- func IsTimestamp(i any) bool
- func NumberCompare(check any, except any, op string) bool
- func StringCompare(check any, except any, op string) bool
- func TimeStampCompare(check any, except any, op string) bool
- func ToNumber(i any) (float64, bool)
- type EvaluateCondition
- type EvaluateUnit
- type InputEvaluateSetUnit
- type InputEvaluateUnit
- type StepFunctionExpression
Constants ¶
This section is empty.
Variables ¶
var ChoiceOperatorArray []string
ChoiceOperatorArray choice operator list
var ChoiceSetOperator = struct { And string Not string Or string None string }{ And: "And", Not: "Not", Or: "Or", None: "None", }
ChoiceSetOperator choice set operator
var CompareCode = struct { GT string GTE string EQ string LT string LTE string }{ GT: "GT", GTE: "GTE", EQ: "EQ", LT: "LT", LTE: "LTE", }
CompareCode compare operators
var CompareFuncs = map[string]func(current any, except any) bool{ Operators.IsBoolean: func(current any, except any) bool { return IsBool(current) == except.(bool) }, Operators.IsNull: func(current any, except any) bool { return IsNull(current) == except.(bool) }, Operators.IsNumeric: func(current any, except any) bool { return IsNumeric(current) == except.(bool) }, Operators.IsString: func(current any, except any) bool { return IsString(current) == except.(bool) }, Operators.IsTimestamp: func(current any, except any) bool { return IsTimestamp(current) == except.(bool) }, Operators.StringEquals: func(current any, except any) bool { return StringCompare(current, except, CompareCode.EQ) }, Operators.StringLessThan: func(current any, except any) bool { return StringCompare(current, except, CompareCode.LT) }, Operators.StringLessThanEquals: func(current any, except any) bool { return StringCompare(current, except, CompareCode.LTE) }, Operators.StringGreaterThan: func(current any, except any) bool { return StringCompare(current, except, CompareCode.GT) }, Operators.StringGreaterThanEquals: func(current any, except any) bool { return StringCompare(current, except, CompareCode.GTE) }, Operators.NumericEquals: func(current any, except any) bool { return NumberCompare(current, except, CompareCode.EQ) }, Operators.NumericLessThan: func(current any, except any) bool { return NumberCompare(current, except, CompareCode.LT) }, Operators.NumericGreaterThan: func(current any, except any) bool { return NumberCompare(current, except, CompareCode.GT) }, Operators.NumericLessThanEquals: func(current any, except any) bool { return NumberCompare(current, except, CompareCode.LTE) }, Operators.NumericGreaterThanEquals: func(current any, except any) bool { return NumberCompare(current, except, CompareCode.GTE) }, Operators.BooleanEquals: func(current any, except any) bool { return current.(bool) == except.(bool) }, }
CompareFuncs compare functions map check if the current value is match to the except value @param current is input variable @param except is evaluate expect value
var ExistFuncs = map[string]func(current bool, except bool) bool{ Operators.IsPresent: func(current bool, except bool) bool { return current == except }, Operators.IsExist: func(current bool, except bool) bool { return current == except }, Operators.VariableExist: func(current bool, except bool) bool { return current == except }, }
ExistFuncs check if the variable is exist return true if the variable match the expect result @param current is input variable is exist @param except is evaluate expect result
var KeyVariable = "Variable"
var Operators = struct { // exist is variable exist VariableExist string IsExist string IsPresent string // Bool is boolean IsBoolean string IsNull string IsNumeric string IsString string IsTimestamp string // String compare StringEquals string StringLessThan string StringGreaterThan string StringLessThanEquals string StringGreaterThanEquals string // Numeric compare NumericEquals string NumericLessThan string NumericGreaterThan string NumericLessThanEquals string NumericGreaterThanEquals string NumericEqualsPath string // bool compare BooleanEquals string // Path string BooleanEqualsPath string // Timestamp compare TimestampEquals string TimestampLessThan string TimestampGreaterThan string TimestampLessThanEquals string TimestampGreaterThanEquals string }{ VariableExist: "VariableExist", IsExist: "IsExist", IsPresent: "IsPresent", IsBoolean: "IsBoolean", IsNull: "IsNull", IsNumeric: "IsNumeric", IsString: "IsString", IsTimestamp: "IsTimestamp", StringEquals: "StringEquals", StringLessThan: "StringLessThan", StringGreaterThan: "StringGreaterThan", StringLessThanEquals: "StringLessThanEquals", StringGreaterThanEquals: "StringGreaterThanEquals", NumericEquals: "NumericEquals", NumericLessThan: "NumericLessThan", NumericGreaterThan: "NumericGreaterThan", NumericLessThanEquals: "NumericLessThanEquals", NumericGreaterThanEquals: "NumericGreaterThanEquals", NumericEqualsPath: "NumericEqualsPath", BooleanEquals: "BooleanEquals", BooleanEqualsPath: "BooleanEqualsPath", TimestampEquals: "TimestampEquals", TimestampLessThan: "TimestampLessThan", TimestampGreaterThan: "TimestampGreaterThan", TimestampLessThanEquals: "TimestampLessThanEquals", TimestampGreaterThanEquals: "TimestampGreaterThanEquals", }
Operators compare operators
Functions ¶
func NumberCompare ¶
NumberCompare compare number @param check is input variable @param except is evaluate expect value @param op is compare operator
func StringCompare ¶
StringCompare compare string @param check is input variable @param except is evaluate expect value @param op is compare operator
func TimeStampCompare ¶
TimeStampCompare compare timestamp
Types ¶
type EvaluateCondition ¶
type EvaluateCondition struct { And []EvaluateCondition Not *EvaluateCondition Or []EvaluateCondition *EvaluateUnit }
EvaluateCondition evaluate condition, combine evaluate unit with And/Or/Not
func ParseEvaluateCondition ¶
func ParseEvaluateCondition(data map[string]any) (*EvaluateCondition, error)
func (*EvaluateCondition) Evaluate ¶
func (ec *EvaluateCondition) Evaluate(input any) bool
func (*EvaluateCondition) Validate ¶
func (ec *EvaluateCondition) Validate(input any) bool
type EvaluateUnit ¶
type EvaluateUnit struct { // compare operate e.g. 'NumberEqual' Operator string // compare value e.g '12' Operand any // variable path e.g '$.foo' Variable string }
EvaluateUnit evaluate unit
func ParseEvaluateUnit ¶
func ParseEvaluateUnit(data map[string]any) (*EvaluateUnit, error)
func (*EvaluateUnit) Evaluate ¶
func (eu *EvaluateUnit) Evaluate(input any) bool
type InputEvaluateSetUnit ¶
type InputEvaluateUnit ¶
type InputEvaluateUnit struct { Variable string `mapstructure:"Variable" validate:"required,gt=0,startswith=$"` // Exist VariableExist bool `mapstructure:"VariableExist"` IsExist bool IsPresent bool // bool 比较 IsBoolean bool `mapstructure:"IsBoolean"` IsNull bool `mapstructure:"IsNull"` IsNumeric bool `mapstructure:"IsNumeric"` IsString bool `mapstructure:"IsString"` IsTimestamp bool `mapstructure:"IsTimestamp"` // value 比较 StringEquals string `mapstructure:"StringEquals"` StringLessThan string `mapstructure:"StringLessThan"` StringGreaterThan string `mapstructure:"StringGreaterThan"` StringLessThanEquals string `mapstructure:"StringLessThanEquals"` StringGreaterThanEquals string `mapstructure:"StringGreaterThanEquals"` NumericEquals float64 `mapstructure:"NumericEquals"` NumericLessThan float64 `mapstructure:"NumericLessThan"` NumericGreaterThan float64 `mapstructure:"NumericGreaterThan"` NumericLessThanEquals float64 `mapstructure:"NumericLessThanEquals"` NumericGreaterThanEquals float64 `mapstructure:"NumericGreaterThanEquals"` TimestampEquals string `mapstructure:"TimestampEquals"` TimestampLessThan string `mapstructure:"TimestampLessThan"` TimestampGreaterThan string `mapstructure:"TimestampGreaterThan"` TimestampLessThanEquals string `mapstructure:"TimestampLessThanEquals"` TimestampGreaterThanEquals string `mapstructure:"TimestampGreaterThanEquals"` BooleanEquals bool `mapstructure:"BooleanEquals"` }
InputEvaluateUnit 基础比较单元
type StepFunctionExpression ¶
type StepFunctionExpression struct {
Expression *EvaluateCondition
}
StepFunctionExpression stepfunction style expression evaluator
func NewStepFunctionExpression ¶
func NewStepFunctionExpression(expression map[string]any) (*StepFunctionExpression, error)
NewStepFunctionExpression create a new stepfunction expression
func (*StepFunctionExpression) Evaluate ¶
func (e *StepFunctionExpression) Evaluate(input any) bool
Evaluate evaluate the expression