stepfunction

package
v0.0.0-...-fefb669 Latest Latest
Warning

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

Go to latest
Published: May 31, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

stepfunction stepfunction style expression evaluator

Index

Constants

This section is empty.

Variables

View Source
var ChoiceOperatorArray []string

ChoiceOperatorArray choice operator list

View Source
var ChoiceSetOperator = struct {
	And  string
	Not  string
	Or   string
	None string
}{
	And:  "And",
	Not:  "Not",
	Or:   "Or",
	None: "None",
}

ChoiceSetOperator choice set operator

View Source
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

View Source
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

View Source
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

View Source
var KeyVariable = "Variable"
View Source
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 IsBool

func IsBool(i any) bool

IsBool check if the value is bool

func IsNull

func IsNull(i any) bool

IsNull check if the value is nil

func IsNumeric

func IsNumeric(i any) bool

IsNumeric check if the value is numeric

func IsString

func IsString(i any) bool

IsString check if the value is string

func IsTimestamp

func IsTimestamp(i any) bool

IsTimestamp check if the value is timestamp

func NumberCompare

func NumberCompare(check any, except any, op string) bool

NumberCompare compare number @param check is input variable @param except is evaluate expect value @param op is compare operator

func StringCompare

func StringCompare(check any, except any, op string) bool

StringCompare compare string @param check is input variable @param except is evaluate expect value @param op is compare operator

func TimeStampCompare

func TimeStampCompare(check any, except any, op string) bool

TimeStampCompare compare timestamp

func ToNumber

func ToNumber(i any) (float64, bool)

ToNumber convert to number float64

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 InputEvaluateSetUnit struct {
	And []map[string]any `mapstructure:"And"`
	Not map[string]any   `mapstructure:"Not"`
	Or  []map[string]any `mapstructure:"Or"`
}

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

Jump to

Keyboard shortcuts

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