MCPcopy Index your code
hub / github.com/apache/casbin / generateEvalFunction

Function generateEvalFunction

enforcer.go:1070–1087  ·  view source on GitHub ↗
(functions map[string]govaluate.ExpressionFunction, parameters *enforceParameters)

Source from the content-addressed store, hash-verified

1068}
1069
1070func 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}

Callers 1

enforceMethod · 0.85

Calls 2

EscapeAssertionFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…