當前位置: 首頁>>代碼示例>>Golang>>正文


Golang EtcdClient.Watch方法代碼示例

本文整理匯總了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
	}
}
開發者ID:vmturbo,項目名稱:kubernetes,代碼行數:27,代碼來源:etcd_watcher.go

示例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
	}
}
開發者ID:resouer,項目名稱:contrib,代碼行數:18,代碼來源:etcd_watcher.go


注:本文中的k8s/io/kubernetes/pkg/tools.EtcdClient.Watch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。