user varargs in store the watch callback

Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
Victor Vieux 2015-05-13 15:18:01 -07:00
parent 54dfabd252
commit 0b45fa5154
5 changed files with 8 additions and 12 deletions

View File

@ -71,7 +71,7 @@ func (s *Discovery) Fetch() ([]*discovery.Entry, error) {
// Watch is exported // Watch is exported
func (s *Discovery) Watch(callback discovery.WatchCallback) { func (s *Discovery) Watch(callback discovery.WatchCallback) {
s.store.WatchRange(s.prefix, "", s.heartbeat, func(kvalues []store.KVEntry) { s.store.WatchRange(s.prefix, "", s.heartbeat, func(kvalues ...store.KVEntry) {
// Traduce byte array entries to discovery.Entry // Traduce byte array entries to discovery.Entry
entries, _ := discovery.CreateEntries(convertToStringArray(kvalues)) entries, _ := discovery.CreateEntries(convertToStringArray(kvalues))
callback(entries) callback(entries)

View File

@ -160,9 +160,7 @@ func (s *Consul) Watch(key string, heartbeat time.Duration, callback WatchCallba
s.watches[fkey] = nil s.watches[fkey] = nil
return err return err
} }
callback(&kviTuple{key, entry, index})
value := []KVEntry{&kviTuple{key, entry, index}}
callback(value)
} }
return nil return nil
@ -230,7 +228,7 @@ func (s *Consul) WatchRange(prefix string, filter string, heartbeat time.Duratio
s.watches[fprefix] = nil s.watches[fprefix] = nil
return err return err
} }
callback(kvi) callback(kvi...)
} }
return nil return nil

View File

@ -153,8 +153,7 @@ func (s *Etcd) Watch(key string, _ time.Duration, callback WatchCallback) error
s.watches[key] = nil s.watches[key] = nil
return err return err
} }
kvi := []KVEntry{&kviTuple{key, entry, index}} callback(&kviTuple{key, entry, index})
callback(kvi)
} }
return nil return nil
} }
@ -242,7 +241,7 @@ func (s *Etcd) WatchRange(prefix string, filter string, _ time.Duration, callbac
s.watches[prefix] = nil s.watches[prefix] = nil
return err return err
} }
callback(kvi) callback(kvi...)
} }
return nil return nil
} }

View File

@ -8,7 +8,7 @@ import (
// WatchCallback is used for watch methods on keys // WatchCallback is used for watch methods on keys
// and is triggered on key change // and is triggered on key change
type WatchCallback func(kviTuple []KVEntry) type WatchCallback func(kviTuple ...KVEntry)
// Initialize creates a new Store object, initializing the client // Initialize creates a new Store object, initializing the client
type Initialize func(addrs []string, options Config) (Store, error) type Initialize func(addrs []string, options Config) (Store, error)

View File

@ -113,9 +113,8 @@ func (s *Zookeeper) Watch(key string, _ time.Duration, callback WatchCallback) e
if e.Type == zk.EventNodeChildrenChanged { if e.Type == zk.EventNodeChildrenChanged {
log.WithField("name", "zk").Debug("Discovery watch triggered") log.WithField("name", "zk").Debug("Discovery watch triggered")
entry, index, err := s.Get(key) entry, index, err := s.Get(key)
kvi := []KVEntry{&kviTuple{key, []byte(entry), index}}
if err == nil { if err == nil {
callback(kvi) callback(&kviTuple{key, []byte(entry), index})
} }
} }
} }
@ -172,7 +171,7 @@ func (s *Zookeeper) WatchRange(prefix string, filter string, _ time.Duration, ca
log.WithField("name", "zk").Debug("Discovery watch triggered") log.WithField("name", "zk").Debug("Discovery watch triggered")
kvi, err := s.GetRange(prefix) kvi, err := s.GetRange(prefix)
if err == nil { if err == nil {
callback(kvi) callback(kvi...)
} }
} }
} }