mirror of https://github.com/docker/docs.git
user varargs in store the watch callback
Signed-off-by: Victor Vieux <victorvieux@gmail.com>
This commit is contained in:
parent
54dfabd252
commit
0b45fa5154
|
@ -71,7 +71,7 @@ func (s *Discovery) Fetch() ([]*discovery.Entry, error) {
|
|||
|
||||
// Watch is exported
|
||||
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
|
||||
entries, _ := discovery.CreateEntries(convertToStringArray(kvalues))
|
||||
callback(entries)
|
||||
|
|
|
@ -160,9 +160,7 @@ func (s *Consul) Watch(key string, heartbeat time.Duration, callback WatchCallba
|
|||
s.watches[fkey] = nil
|
||||
return err
|
||||
}
|
||||
|
||||
value := []KVEntry{&kviTuple{key, entry, index}}
|
||||
callback(value)
|
||||
callback(&kviTuple{key, entry, index})
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -230,7 +228,7 @@ func (s *Consul) WatchRange(prefix string, filter string, heartbeat time.Duratio
|
|||
s.watches[fprefix] = nil
|
||||
return err
|
||||
}
|
||||
callback(kvi)
|
||||
callback(kvi...)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -153,8 +153,7 @@ func (s *Etcd) Watch(key string, _ time.Duration, callback WatchCallback) error
|
|||
s.watches[key] = nil
|
||||
return err
|
||||
}
|
||||
kvi := []KVEntry{&kviTuple{key, entry, index}}
|
||||
callback(kvi)
|
||||
callback(&kviTuple{key, entry, index})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -242,7 +241,7 @@ func (s *Etcd) WatchRange(prefix string, filter string, _ time.Duration, callbac
|
|||
s.watches[prefix] = nil
|
||||
return err
|
||||
}
|
||||
callback(kvi)
|
||||
callback(kvi...)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
// WatchCallback is used for watch methods on keys
|
||||
// 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
|
||||
type Initialize func(addrs []string, options Config) (Store, error)
|
||||
|
|
|
@ -113,9 +113,8 @@ func (s *Zookeeper) Watch(key string, _ time.Duration, callback WatchCallback) e
|
|||
if e.Type == zk.EventNodeChildrenChanged {
|
||||
log.WithField("name", "zk").Debug("Discovery watch triggered")
|
||||
entry, index, err := s.Get(key)
|
||||
kvi := []KVEntry{&kviTuple{key, []byte(entry), index}}
|
||||
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")
|
||||
kvi, err := s.GetRange(prefix)
|
||||
if err == nil {
|
||||
callback(kvi)
|
||||
callback(kvi...)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue