casbin
casbin copied to clipboard
[Question] incomplete method list of SyncedEnforcer
There are some functions lacking in SyncedEnforcer
, i.e., SetAdapter()
.
I don't think we can always keep them consistent, so can we add a lock-wrapped interface for compatibility?
A proof-of-concept:
func (e *SyncedEnforcer) RunSynced(f func()) {
e.m.Lock()
defer e.m.Unlock()
f()
}
//usage
var res [][]string
e.RunSynced(func() {
e.Enforcer.SetAdapter(a)
res = e.Enforcer.GetPolicy()
})
More comparision on supported methods:
@tangyang9464 @JalinWang
@JalinWang your method looks interesting. It can be added. But we cannot remove the old way for back compatibility either.
@JalinWang I don't see any difference from the previous approach, doesn't this approach also need to deal with each method?
@tangyang9464 e.m
is a private member which can't be accessed outside. However, we don't always keep SyncedEnforcer
updated with Enforcer
, e.g., SetAdapter()
is missed in the synced one.
I want to provide such a function (or just exposing the internal lock is okay) for users to use the missed method and leave the existing supported methods unchanged.
@JalinWang I think we should always maintain the consistency of the two SyncedEnforcer and Enforcer APIs, instead of providing RunSync, it is not easy to use, and users are prone to misuse
I agree with @tangyang9464 , so closed here for now, we can do offline discussions further if needed