Effector
The Effect represents policy rule outcomes, while the Effector interface manages effect handling within Casbin.
MergeEffects()
The MergeEffects() function consolidates all matching results gathered by the enforcer into one final decision.
ตัวอย่างเช่น:
Effect, explainIndex, err = e.MergeEffects(expr, effects, matches, policyIndex, policyLength)
Explanation of parameters:
Effectrepresents the final merged decision (initialized asIndeterminate).explainIndexholds theeftindex (AlloworDeny), initialized at-1.errverifies effect support.exprcontains the string representation of policy effects.effectsis an array containingAllow,Indeterminate, orDenyvalues.matchesindicates which results match policies.policyIndexidentifies the policy position in the model.policyLengthspecifies the policy count.
The example demonstrates parameter passing to MergeEffects(), which processes effects and matches according to the expr.
To utilize the Effector:
var e Effector
Effect, explainIndex, err = e.MergeEffects(expr, effects, matches, policyIndex, policyLength)
The core concept of MergeEffects(): when expr matches results indicating p_eft is allow, effects merge together. Absent deny rule matches result in an allow decision.
หมายเหตุ
When expr doesn't match "priority(p_eft) || deny" and policyIndex is less than policyLength-1, short-circuiting occurs, skipping intermediate effects.