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


Golang Client.Delete方法代碼示例

本文整理匯總了Golang中github.com/coreos/etcd/clientv3.Client.Delete方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Delete方法的具體用法?Golang Client.Delete怎麽用?Golang Client.Delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/coreos/etcd/clientv3.Client的用法示例。


在下文中一共展示了Client.Delete方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: deletePrefix

func deletePrefix(ctx context.Context, client *clientv3.Client, key string) error {
	for ctx.Err() == nil {
		if _, err := client.Delete(ctx, key, clientv3.WithPrefix()); err == nil {
			return nil
		}
	}
	return ctx.Err()
}
開發者ID:pulcy,項目名稱:vault-monkey,代碼行數:8,代碼來源:watcher.go

示例2: syncProcess_v3FSEvent

func syncProcess_v3FSEvent(localDir string, serverPrefix string, c3 *clientv3.Client, event fileChangeEvent) {
	etcdPath, err := filepath.Rel(localDir, event.Path)
	if err != nil {
		log.Printf("syncProcess_v3 error get relpath '%v': %v\n", event.Path, err)
		return
	}
	etcdPath = serverPrefix + etcdPath
	etcdPath = strings.Replace(etcdPath, string(os.PathSeparator), "/", -1)

	switch {
	case event.IsRemoved:
		_, err := c3.Delete(context.Background(), etcdPath)
		if err != nil {
			log.Printf("syncProcess_v3 error while delete etcdkey '%v': %v\n", etcdPath, err)
		}
	case event.IsDir:
		files, _ := ioutil.ReadDir(event.Path)
		for _, file := range files {
			path := filepath.Join(event.Path, file.Name())
			content := []byte(nil)
			if !file.IsDir() {
				content, err = ioutil.ReadFile(path)
				if err != nil {
					log.Println(err)
				}
			}
			syncProcess_v3FSEvent(localDir, serverPrefix, c3, fileChangeEvent{
				Path:      path,
				IsDir:     file.IsDir(),
				IsRemoved: false,
				Content:   content,
			})
		}
	case !event.IsDir:
		resp, err := c3.Get(context.Background(), etcdPath)
		if err != nil {
			log.Printf("syncProcess_v3 Can't read key '%v': %v\n", etcdPath, err)
		}
		if len(resp.Kvs) > 0 {
			if bytes.Equal(resp.Kvs[0].Value, event.Content) {
				return
			}
		}
		_, err = c3.Put(context.Background(), etcdPath, string(event.Content))
		if err != nil {
			log.Printf("syncProcess_v3 error while put etcdkey '%v': %v\n", etcdPath, err)
		}
	}
}
開發者ID:rekby,項目名稱:etcddir,代碼行數:49,代碼來源:v3.go


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