Documentation ¶
Index ¶
- func DefaultUpdateCallback(e casbin.IEnforcer) func(string)
- func NewPublishWatcher(addr string, option WatcherOptions) (persist.Watcher, error)
- func NewWatcher(addr string, option WatcherOptions) (persist.Watcher, error)
- func NewWatcherWithCluster(addrs string, option WatcherOptions) (persist.Watcher, error)
- type MSG
- type UpdateType
- type Watcher
- func (w *Watcher) Close()
- func (w *Watcher) GetWatcherOptions() WatcherOptions
- func (w *Watcher) SetUpdateCallback(callback func(string)) error
- func (w *Watcher) Update() error
- func (w *Watcher) UpdateForAddPolicies(sec string, ptype string, rules ...[]string) error
- func (w *Watcher) UpdateForAddPolicy(sec, ptype string, params ...string) error
- func (w *Watcher) UpdateForRemoveFilteredPolicy(sec, ptype string, fieldIndex int, fieldValues ...string) error
- func (w *Watcher) UpdateForRemovePolicies(sec string, ptype string, rules ...[]string) error
- func (w *Watcher) UpdateForRemovePolicy(sec, ptype string, params ...string) error
- func (w *Watcher) UpdateForSavePolicy(model model.Model) error
- func (w *Watcher) UpdateForUpdatePolicies(sec string, ptype string, oldRules, newRules [][]string) error
- func (w *Watcher) UpdateForUpdatePolicy(sec string, ptype string, oldRule, newRule []string) error
- type WatcherOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultUpdateCallback ¶ added in v2.1.0
func DefaultUpdateCallback(e casbin.IEnforcer) func(string)
func NewPublishWatcher ¶
func NewPublishWatcher(addr string, option WatcherOptions) (persist.Watcher, error)
NewPublishWatcher return a Watcher only publish but not subscribe
func NewWatcher ¶
func NewWatcher(addr string, option WatcherOptions) (persist.Watcher, error)
NewWatcher creates a new Watcher to be used with a Casbin enforcer addr is a redis target string in the format "host:port" setters allows for inline WatcherOptions
Example: w, err := rediswatcher.NewWatcher("127.0.0.1:6379",WatcherOptions{}, nil)
func NewWatcherWithCluster ¶
func NewWatcherWithCluster(addrs string, option WatcherOptions) (persist.Watcher, error)
NewWatcherWithCluster creates a new Watcher to be used with a Casbin enforcer addrs is a redis-cluster target string in the format "host1:port1,host2:port2,host3:port3"
Example: w, err := rediswatcher.NewWatcherWithCluster("127.0.0.1:6379,127.0.0.1:6379,127.0.0.1:6379",WatcherOptions{})
Types ¶
type MSG ¶
type MSG struct { Method UpdateType ID string Sec string Ptype string OldRule []string OldRules [][]string NewRule []string NewRules [][]string FieldIndex int FieldValues []string }
func (*MSG) MarshalBinary ¶
func (*MSG) UnmarshalBinary ¶
UnmarshalBinary decodes the struct into a User
type UpdateType ¶ added in v2.1.0
type UpdateType string
const ( Update UpdateType = "Update" UpdateForAddPolicy UpdateType = "UpdateForAddPolicy" UpdateForRemovePolicy UpdateType = "UpdateForRemovePolicy" UpdateForRemoveFilteredPolicy UpdateType = "UpdateForRemoveFilteredPolicy" UpdateForSavePolicy UpdateType = "UpdateForSavePolicy" UpdateForAddPolicies UpdateType = "UpdateForAddPolicies" UpdateForRemovePolicies UpdateType = "UpdateForRemovePolicies" UpdateForUpdatePolicy UpdateType = "UpdateForUpdatePolicy" UpdateForUpdatePolicies UpdateType = "UpdateForUpdatePolicies" )
type Watcher ¶
type Watcher struct {
// contains filtered or unexported fields
}
func (*Watcher) GetWatcherOptions ¶
func (w *Watcher) GetWatcherOptions() WatcherOptions
func (*Watcher) SetUpdateCallback ¶
SetUpdateCallback sets the update callback function invoked by the watcher when the policy is updated. Defaults to Enforcer.LoadPolicy()
func (*Watcher) Update ¶
Update publishes a message to all other casbin instances telling them to invoke their update callback
func (*Watcher) UpdateForAddPolicies ¶
UpdateForAddPolicies calls the update callback of other instances to synchronize their policies in batch. It is called after Enforcer.AddPolicies()
func (*Watcher) UpdateForAddPolicy ¶
UpdateForAddPolicy calls the update callback of other instances to synchronize their policy. It is called after Enforcer.AddPolicy()
func (*Watcher) UpdateForRemoveFilteredPolicy ¶
func (w *Watcher) UpdateForRemoveFilteredPolicy(sec, ptype string, fieldIndex int, fieldValues ...string) error
UpdateForRemoveFilteredPolicy calls the update callback of other instances to synchronize their policy. It is called after Enforcer.RemoveFilteredNamedGroupingPolicy()
func (*Watcher) UpdateForRemovePolicies ¶
UpdateForRemovePolicies calls the update callback of other instances to synchronize their policies in batch. It is called after Enforcer.RemovePolicies()
func (*Watcher) UpdateForRemovePolicy ¶
UpdateForRemovePolicy calls the update callback of other instances to synchronize their policy. It is called after Enforcer.RemovePolicy()
func (*Watcher) UpdateForSavePolicy ¶
UpdateForSavePolicy calls the update callback of other instances to synchronize their policy. It is called after Enforcer.RemoveFilteredNamedGroupingPolicy()
func (*Watcher) UpdateForUpdatePolicies ¶ added in v2.2.0
func (w *Watcher) UpdateForUpdatePolicies(sec string, ptype string, oldRules, newRules [][]string) error
UpdateForUpdatePolicies calls the update callback of other instances to synchronize their policy. It is called after Enforcer.UpdatePolicies()