本文整理匯總了Golang中k8s/io/kubernetes/pkg/tools.EtcdClient.Watch方法的典型用法代碼示例。如果您正苦於以下問題:Golang EtcdClient.Watch方法的具體用法?Golang EtcdClient.Watch怎麽用?Golang EtcdClient.Watch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類k8s/io/kubernetes/pkg/tools.EtcdClient
的用法示例。
在下文中一共展示了EtcdClient.Watch方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: etcdWatch
// etcdWatch calls etcd's Watch function, and handles any errors. Meant to be called
// as a goroutine.
func (w *etcdWatcher) etcdWatch(client tools.EtcdClient, key string, resourceVersion uint64) {
// glog.Infof("Watching")
defer util.HandleCrash()
defer close(w.etcdError)
if resourceVersion == 0 {
latest, err := etcdGetInitialWatchState(client, key, w.list, w.etcdIncoming)
if err != nil {
if etcdError, ok := err.(*etcd.EtcdError); ok && etcdError != nil && etcdError.ErrorCode == tools.EtcdErrorCodeNotFound {
// glog.Errorf("Error getting initial watch, key not found: %v", err)
return
}
glog.Errorf("Error getting initial watch: %v", err)
w.etcdError <- err
return
}
resourceVersion = latest + 1
}
response, err := client.Watch(key, resourceVersion, w.list, w.etcdIncoming, w.etcdStop)
glog.Infof("response is %v", response)
if err != nil && err != etcd.ErrWatchStoppedByUser {
glog.Errorf("Error watch: %v", err)
w.etcdError <- err
}
}
示例2: etcdWatch
// etcdWatch calls etcd's Watch function, and handles any errors. Meant to be called
// as a goroutine.
func (w *etcdWatcher) etcdWatch(client tools.EtcdClient, key string, resourceVersion uint64) {
defer util.HandleCrash()
defer close(w.etcdError)
if resourceVersion == 0 {
latest, err := etcdGetInitialWatchState(client, key, w.list, w.etcdIncoming)
if err != nil {
w.etcdError <- err
return
}
resourceVersion = latest + 1
}
_, err := client.Watch(key, resourceVersion, w.list, w.etcdIncoming, w.etcdStop)
if err != nil && err != etcd.ErrWatchStoppedByUser {
w.etcdError <- err
}
}