Effector
The Effect represents the result of a policy rule, and the Effector is the interface for handling effects in Casbin.
MergeEffects()
The MergeEffects() function is used to merge all matching results collected by the enforcer into a single decision.
For example:
- Go
Effect, explainIndex, err = e.MergeEffects(expr, effects, matches, policyIndex, policyLength)
In this example:
Effectis the final decision that is merged by this function (initialized asIndeterminate).explainIndexis the index ofeft(AlloworDeny), and it is initialized as-1.erris used to check if the effect is supported.expris the string representation of the policy effects.effectsis an array of effects, which can beAllow,Indeterminate, orDeny.matchesis an array that indicates whether the result matches the policy.policyIndexis the index of the policy in the model.policyLengthis the length of the policy.
The code above illustrates how to pass the parameters to the MergeEffects() function, and the function will process the effects and matches based on the expr.
To use the Effector, follow these steps:
- Go
var e Effector
Effect, explainIndex, err = e.MergeEffects(expr, effects, matches, policyIndex, policyLength)
The basic idea of MergeEffects() is that if the expr can match the results, indicating that the p_eft is allow, then all effects can be merged. If no deny rules are matched, then the decision is allow.
If the expr does not match the condition "priority(p_eft) || deny", and the policyIndex is shorter than policyLength-1, it will short-circuit some effects in the middle.