Перейти к основному контенту

Эффект

The Effect represents the result of a policy rule, and the Effector is the interface for handling effects in Casbin.

Эффекты слияния ()

The MergeEffects() function is used to merge all matching results collected by the enforcer into a single decision.

Например:

Effect, explainIndex, err = e.MergeEffects(expr, effects, matches, policyIndex, policyLength)

В этом примере:

  • Effect is the final decision that is merged by this function (initialized as Indeterminate).
  • explainIndex is the index of eft (Allow or Deny), and it is initialized as -1.
  • err используется для проверки поддерживаемого эффекта.
  • expr is the string representation of the policy effects.
  • effects is an array of effects, which can be Allow, Indeterminate, or Deny.
  • 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:

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.

::note

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.

:::