Documentation ¶
Index ¶
- func DefaultCallback(e casbin.IEnforcer) func(string)
- type MSG
- type Option
- type UpdateType
- type Watcher
- func (w *Watcher) Close()
- func (w *Watcher) GetChannel() string
- func (w *Watcher) GetLocalID() string
- func (w *Watcher) GetNotifySelf() bool
- func (w *Watcher) GetVerbose() bool
- 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
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultCallback ¶
func DefaultCallback(e casbin.IEnforcer) func(string)
DefaultCallback defines the generic implementation for WatcherEX interface.
Types ¶
type MSG ¶
type MSG struct { Method UpdateType `json:"method"` ID string `json:"id"` Sec string `json:"sec,omitempty"` Ptype string `json:"ptype,omitempty"` OldRules [][]string `json:"old_rules,omitempty"` NewRules [][]string `json:"new_rules,omitempty"` FieldIndex int `json:"field_index,omitempty"` FieldValues []string `json:"field_values,omitempty"` }
MSG defines the payload for message.
type Option ¶
type Option struct { // Channel defines which psql channel to use. // use default channel if not specified. Channel string // Verbose indicate whether to output info log. Verbose bool // LocalID indicates the watcher's local ID, used to ignore self update event. // generate a random id if not specified. LocalID string // NotifySelf will notify change to the same watcher to do the update. // only for testing or debug usage. NotifySelf bool }
Option is used for configure watcher.
type UpdateType ¶
type UpdateType string
UpdateType defines the type of update operation.
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" )
all types of Update.
type Watcher ¶
Watcher implements casbin Watcher and WatcherEX to sync multiple casbin enforcer.
func NewWatcherWithConnString ¶
NewWatcherWithConnString creates a Watcher with pgx connection string.
func NewWatcherWithPool ¶
NewWatcherWithPool creates a Watcher with pgx pool.
func (*Watcher) Close ¶
func (w *Watcher) Close()
Close stops and releases the watcher, the callback function will not be called any more.
func (*Watcher) GetChannel ¶
GetChannel gets the channel for the option.
func (*Watcher) GetLocalID ¶
GetLocalID gets the local ID for the option.
func (*Watcher) GetNotifySelf ¶
GetNotifySelf gets the NotifySelf for the option.
func (*Watcher) GetVerbose ¶
GetVerbose gets the verbose for the option.
func (*Watcher) SetUpdateCallback ¶
SetUpdateCallback sets the callback function that the watcher will call when the policy in DB has been changed by other instances. A classic callback is Enforcer.LoadPolicy().
func (*Watcher) Update ¶
Update calls the update callback of other instances to synchronize their policy. It is usually called after changing the policy in DB, like Enforcer.SavePolicy(), Enforcer.AddPolicy(), Enforcer.RemovePolicy(), etc.
func (*Watcher) UpdateForAddPolicies ¶
UpdateForAddPolicies calls the update callback of other instances to synchronize their policy. 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 policy. 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()