エフェクト
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.
例:
- Go
Effect, explainIndex, err = e.MergeEffects(expr, effects, matches, policyIndex, policyLength)
この例では:
Effect
is the final decision that is merged by this function (initialized asIndeterminate
).explainIndex
is the index ofeft
(Allow
orDeny
), and it is initialized as-1
.err
は効果がサポートされているかどうかを確認するために使用されます。expr
is the string representation of the policy effects.effects
is an array of effects, which can beAllow
,Indeterminate
, orDeny
.matches
is an array that indicates whether the result matches the policy.policyIndex
is the index of the policy in the model.ポリシー長さ
はポリシーの長さです。
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.