MCPcopy
hub / github.com/apache/casbin / SetWatcher

Method SetWatcher

enforcer.go:245–254  ·  view source on GitHub ↗

SetWatcher sets the current watcher.

(watcher persist.Watcher)

Source from the content-addressed store, hash-verified

243
244// SetWatcher sets the current watcher.
245func (e *Enforcer) SetWatcher(watcher persist.Watcher) error {
246 e.watcher = watcher
247 if _, ok := e.watcher.(persist.WatcherEx); ok {
248 // The callback of WatcherEx has no generic implementation.
249 return nil
250 } else {
251 // In case the Watcher wants to use a customized callback function, call `SetUpdateCallback` after `SetWatcher`.
252 return watcher.SetUpdateCallback(func(string) { _ = e.LoadPolicy() })
253 }
254}
255
256// GetRoleManager gets the current role manager.
257func (e *Enforcer) GetRoleManager() rbac.RoleManager {

Callers 4

TestSetWatcherExFunction · 0.95
TestSetWatcherFunction · 0.95
TestSelfModifyFunction · 0.95
TestSetWatcherUpdatableFunction · 0.95

Calls 2

LoadPolicyMethod · 0.95
SetUpdateCallbackMethod · 0.65

Tested by 4

TestSetWatcherExFunction · 0.76
TestSetWatcherFunction · 0.76
TestSelfModifyFunction · 0.76
TestSetWatcherUpdatableFunction · 0.76