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().
(callback func(string))
| 141 | // when the policy in DB has been changed by other instances. |
| 142 | // A classic callback is Enforcer.LoadPolicy(). |
| 143 | func (w *Watcher) SetUpdateCallback(callback func(string)) error { |
| 144 | w.lock.Lock() |
| 145 | defer w.lock.Unlock() |
| 146 | w.callback = callback |
| 147 | return nil |
| 148 | } |
| 149 | |
| 150 | // Update calls the update callback of other instances to synchronize their policy. |
| 151 | // It is usually called after changing the policy in DB, like Enforcer.SavePolicy(), |
no outgoing calls