(functions map[string]govaluate.ExpressionFunction, parameters *enforceParameters)
| 1068 | } |
| 1069 | |
| 1070 | func generateEvalFunction(functions map[string]govaluate.ExpressionFunction, parameters *enforceParameters) govaluate.ExpressionFunction { |
| 1071 | return func(args ...interface{}) (interface{}, error) { |
| 1072 | if len(args) != 1 { |
| 1073 | return nil, fmt.Errorf("function eval(subrule string) expected %d arguments, but got %d", 1, len(args)) |
| 1074 | } |
| 1075 | |
| 1076 | expression, ok := args[0].(string) |
| 1077 | if !ok { |
| 1078 | return nil, errors.New("argument of eval(subrule string) must be a string") |
| 1079 | } |
| 1080 | expression = util.EscapeAssertion(expression) |
| 1081 | expr, err := govaluate.NewEvaluableExpressionWithFunctions(expression, functions) |
| 1082 | if err != nil { |
| 1083 | return nil, fmt.Errorf("error while parsing eval parameter: %s, %s", expression, err.Error()) |
| 1084 | } |
| 1085 | return expr.Eval(parameters) |
| 1086 | } |
| 1087 | } |
no test coverage detected
searching dependent graphs…