feat: fix panic on empty Events array in etcd watch response (#36)
diff --git a/go.mod b/go.mod index 503070f..602455d 100644 --- a/go.mod +++ b/go.mod
@@ -4,6 +4,5 @@ require ( github.com/casbin/casbin/v2 v2.30.2 - go.etcd.io/etcd/api/v3 v3.5.0 go.etcd.io/etcd/client/v3 v3.5.0 )
diff --git a/watcher.go b/watcher.go index 9abd559..329d2a8 100644 --- a/watcher.go +++ b/watcher.go
@@ -164,6 +164,14 @@ func (w *Watcher) startWatch() error { watcher := w.client.Watch(context.Background(), w.keyName) for res := range watcher { + // Skip progress notifications + if res.IsProgressNotify() { + continue + } + // Skip empty events + if len(res.Events) == 0 { + continue + } t := res.Events[0] if t.IsCreate() || t.IsModify() { w.lock.RLock()