| 907 | } |
| 908 | |
| 909 | func (e *Enforcer) getAndStoreMatcherExpression(hasEval bool, expString string, functions map[string]govaluate.ExpressionFunction) (*govaluate.EvaluableExpression, error) { |
| 910 | var expression *govaluate.EvaluableExpression |
| 911 | var err error |
| 912 | var cachedExpression, isPresent = e.matcherMap.Load(expString) |
| 913 | |
| 914 | if !hasEval && isPresent { |
| 915 | expression = cachedExpression.(*govaluate.EvaluableExpression) |
| 916 | } else { |
| 917 | expression, err = govaluate.NewEvaluableExpressionWithFunctions(expString, functions) |
| 918 | if err != nil { |
| 919 | return nil, err |
| 920 | } |
| 921 | e.matcherMap.Store(expString, expression) |
| 922 | } |
| 923 | return expression, nil |
| 924 | } |
| 925 | |
| 926 | // Enforce decides whether a "subject" can access a "object" with the operation "action", input parameters are usually: (sub, obj, act). |
| 927 | func (e *Enforcer) Enforce(rvals ...interface{}) (bool, error) { |