Dispatchers
Dispatcher 把 增量 的策略更新传播到多个 enforcer 实例(例如一个集群)。它们使用一致性协议(例如 Raft),让所有 enforcer 最终看到同一份策略。 Casbin 的常规 API(AddPolicy、RemovePolicy 等)保持不变;dispatcher 负责把更新发送到其他节点。
分为两部分:(1) Casbin 内部由 dispatcher 实现的钩子;(2) dispatcher 自身的配置(例如集群成员、配置项)。
备注
Dispatcher 只同步初始化之后的 变更。它们 不会 修复已有的不一致。启用 dispatcher 之前,让所有 enforcer 以同一份策略启动(例如来自同一个数据库或快照)。
可用的 dispatcher:
| Adapter | Type | Author | Description |
|---|---|---|---|
| Hashicorp Raft Dispatcher | Raft | Casbin | A dispatcher based on Hashicorp Raft |
| KDKYG/casbin-dispatcher | Raft | @KDKYG | A dispatcher based on Hashicorp Raft |
DistributedEnforcer
DistributedEnforcer 包装了 SyncedEnforcer,以配合 dispatcher 使用。
e, _ := casbin.NewDistributedEnforcer("examples/basic_model.conf", "examples/basic_policy.csv")
Comments are powered by giscus and GitHub Discussions. They load from giscus.app and GitHub only after you click the button below.