SetWatcher sets the current watcher.
(watcher persist.Watcher)
| 243 | |
| 244 | // SetWatcher sets the current watcher. |
| 245 | func (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. |
| 257 | func (e *Enforcer) GetRoleManager() rbac.RoleManager { |