Effector
Effect is the result of a policy rule. And the Effector
is the interface for Casbin effectors.
MergeEffects()
MergeEffects merges 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:
Effect
is the final decision being merged by this function(Initialized asIndeterminate
).explainIndex
is the index ofeft
which isAllow
orDeny
.(Initialized as-1
)err
is used to check if the effect is supported.expr
is the policy effects stored asstring
effects
is the array of the Effect which can beAllow
,Indeterminate
orDeny
matches
is the array showing that if the result is matching the policy.policyIndex
is the index of policy in the model.policyLength
is the length of the policy.
The code above illustrates how can we pass the parameters to the MergeEffects
function and the function will process the effects and matches based on the expr
To deploy an Effector, we can do this:
- Go
var e Effector
Effect, explainIndex, err = e.MergeEffects(expr, effects, matches, policyIndex, policyLength)
The basic idea of the MergeEffects
indicates that if the expr
can match the results which means that the p_eft
is allow
, then we can merge all effects at last. And if there are no deny rules are matched, then we allow.
note
If the expr
can not match "priority(p_eft) || deny"
and also the policyIndex
is shorter than policyLength-1
, it will short-circuit some effects in the middle.