当前位置: 首页>>代码示例>>Golang>>正文


Golang Client.SetDir方法代码示例

本文整理汇总了Golang中github.com/coreos/go-etcd/etcd.Client.SetDir方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.SetDir方法的具体用法?Golang Client.SetDir怎么用?Golang Client.SetDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/coreos/go-etcd/etcd.Client的用法示例。


在下文中一共展示了Client.SetDir方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: etcdClientSetUp

func etcdClientSetUp(t *testing.T, rawClient *etcd.Client) map[string]interface{} {
	var err error
	if _, err = rawClient.SetDir("test", 0); err != nil {
		t.Fatal(err)
	}
	if _, err = rawClient.Set("test/index", "1", 0); err != nil {
		t.Fatal(err)
	}
	if _, err = rawClient.SetDir("test/values", 0); err != nil {
		t.Fatal(err)
	}
	if _, err = rawClient.Set("test/values/a", "aye", 0); err != nil {
		t.Fatal(err)
	}
	if _, err = rawClient.Set("test/values/b", "bee", 0); err != nil {
		t.Fatal(err)
	}

	want := make(map[string]interface{})
	wantValues := make(map[string]interface{})
	wantValues["a"] = "aye"
	wantValues["b"] = "bee"
	want["values"] = wantValues
	want["index"] = "1"
	return want
}
开发者ID:BlueDragonX,项目名称:sentinel,代码行数:26,代码来源:client_test.go

示例2: EtcdMkDir

func EtcdMkDir(client *etcd.Client, path string, ttl uint64) error {
	_, err := client.SetDir(path, ttl)
	if err != nil {
		return err
	}
	return nil
}
开发者ID:xingskycn,项目名称:duang,代码行数:7,代码来源:utils.go

示例3: setDirCommandFunc

func setDirCommandFunc(cmd *cobra.Command, args []string, client *etcd.Client) (*etcd.Response, error) {
	if len(args) == 0 {
		return nil, errors.New("Key required")
	}
	key := args[0]
	ttl := ttlFlag

	return client.SetDir(key, uint64(ttl))
}
开发者ID:joshi4,项目名称:etcdctl,代码行数:9,代码来源:set_dir_command.go

示例4: RegisterService

func RegisterService(client *etcd.Client, service services.Service, ttl time.Duration) {
	keyPrefix := fmt.Sprintf("/services/%s/%s/", service.Service, service.Id)
	var attributes map[string]string = make(map[string]string)
	attributes["address"] = service.Address
	for key, value := range service.Labels {
		if key == "address" {
			fmt.Println("WARNING: overriding address(%s) with label: %s", service.Address, value)
		}
		attributes[key] = value
	}

	// create service/id dir with ttl
	client.SetDir(keyPrefix, uint64(ttl.Seconds()))
	for key, value := range attributes {
		_, err := client.Set(keyPrefix+key, value, 0)
		if err != nil {
			fmt.Println(err)
			// abort current registration
			return
		}
	}
}
开发者ID:durl,项目名称:registrator,代码行数:22,代码来源:registry.go

示例5: TestNodeFs

func TestNodeFs(t *testing.T) {
	g := Goblin(t)

	g.Describe("File", func() {
		var etcd *etcdm.Client
		var fs testEtcdFsMount

		g.Before(func() {
			etcd = etcdm.NewClient([]string{testEtcdEndpoint})
		})

		g.BeforeEach(func() {
			etcd.RawDelete("/test", true, true)
			etcd.SetDir("/test", 0)
			fs = NewTestEtcdFsMount()
		})

		g.AfterEach(func() {
			fs.Unmount()
		})

		g.Describe("Open", func() {
			g.It("Should be supported", func() {
				if _, e := etcd.Set("/test/foo", "bar", 0); e != nil {
					g.Fail(e)
				}

				file, err := os.Open(fs.Path() + "/test/foo")

				if err != nil {
					g.Fail(err)
				}

				file.Close()
			})
		})
		g.Describe("Create", func() {
			g.It("Should be supported", func() {
				file, err := os.Create(fs.Path() + "/test/bar")

				if err != nil {
					g.Fail(err)
				}
				file.Close()

				if _, er := etcd.Get("/test/bar", false, false); er != nil {
					g.Fail(er)
				}
			})
		})
		g.Describe("Delete", func() {
			g.It("Should be supported", func() {
				etcd.Set("/test/barfoo", "lala", 0)

				err := os.Remove(fs.Path() + "/test/barfoo")

				if err != nil {
					g.Fail(err)
				}

				if _, er := etcd.Get("/test/barfoo", false, false); er == nil {
					g.Fail("The key [/test/barfoo] should not exist")
				}
			})
		})
		g.Describe("Read", func() {
			g.It("Should be supported", func() {
				etcd.Set("/test/bar", "foo", 0)

				data, err := ioutil.ReadFile(fs.Path() + "/test/bar")

				if err != nil {
					g.Fail(err)
				}

				g.Assert(string(data)).Equal("foo")
			})
		})
		g.Describe("Write", func() {
			g.It("Should be supported", func() {
				if err := ioutil.WriteFile(fs.Path()+"/test/foobar", []byte("hello world"), 0666); err != nil {
					g.Fail(err)
				}

				res, err := etcd.Get("/test/foobar", false, false)

				if err != nil {
					g.Fail(err)
				}

				g.Assert(res.Node.Value).Equal("hello world")
			})
		})
	})
}
开发者ID:roberto-reale,项目名称:etcd-fs,代码行数:95,代码来源:file_test.go

示例6: Pusher


//.........这里部分代码省略.........
	}

	configInfo := config.ConfigInfo{
		Repo:    repo,
		Branch:  branch,
		Version: commitHash,
		Commit: config.CommitInfo{
			TimeStamp:      timestamp,
			CommitterEmail: email,
			Subject:        subject,
		},
		ModFiles:   *modFiles,
		PathToRepo: pathToRepo,
	}

	jsonBytes, err := json.Marshal(configInfo)
	if err != nil {
		log.Fatalf("error when marshal configInfo, err: %s", err)
	}
	fmt.Printf("ConfigInfo json: %s\n", string(jsonBytes[:len(jsonBytes)]))

	// Get previous pusher information from root node for sanity check.
	if !etcdHasCommit {
		promptUser("There is no existing commit in remote tree. It could because " +
			"you're pushing to a clean tree. Do you want to continue?")
	} else {
		// Sanity check of pusher info.
		if configInfo.Repo != prevCFG.Repo {
			promptUser("Repo to be pushed <%s> != remote repo name <%s>. Continue?",
				configInfo.Repo, prevCFG.Repo)
		}
		if configInfo.Branch != prevCFG.Branch {
			promptUser("Branch to be pushed <%s> != remote branch <%s>. Continue?",
				configInfo.Branch, prevCFG.Branch)
		}
		if configInfo.PathToRepo != prevCFG.PathToRepo {
			promptUser("Path to repo <%s> != remote path <%s>. Continue?",
				configInfo.PathToRepo, prevCFG.PathToRepo)
		}
	}

	keys := make([]string, len(content))
	// sort content's keys
	i := 0
	for k := range content {
		keys[i] = k
		i++
	}
	sort.Strings(keys)

	// set etcd content.
	for _, k := range keys {
		fileP := filepath.Join(remoteRoot, k)
		fmt.Printf("creating or setting %s\n", fileP)
		if content[k].isDir {
			if _, err := etcdConn.Get(fileP, true, false); err != nil {
				// dir doesn't exist
				resp, err = etcdConn.SetDir(fileP, 0)
			}
		} else {
			resp, err = etcdConn.Set(fileP, string(content[k].content), 0)
		}
		if err != nil {
			log.Fatalf("error when setting znode >%s(%s + %s)<. Config server will be inconsistent: %s",
				fileP, remoteRoot, k, err)
		}
	}

	// go over deletes in commit
	for _, mod := range *modFiles {
		if strings.ToLower(mod.Op) != "d" {
			continue
		}
		// it's a delete
		// Find the relative path to etcd root.
		fileP := filepath.Join(remoteRoot, mod.Path)
		fmt.Printf("deleting %s (%s + %s)\n", fileP, remoteRoot, mod.Path)
		_, err = etcdConn.Delete(fileP, true)
		if err != nil {
			log.Errorf("error deleting file >%s<. Will continue. error: %s\n", fileP, err)
		}
		// since git uses a file as  a commit unit, there is nothing to do with folder.
		// what we are going to do is to delete each fileP which is modified with "d" and its corresponding folder.
		// If we still have children under that folder, deleting the folder will fail but we do not care.
		pDir := filepath.Join(remoteRoot, path.Dir(mod.Path))
		_, err = etcdConn.DeleteDir(pDir)
		// In normal case, we should get an error.
		// so just logging, if we have no error here.
		if err == nil {
			log.Errorf("error deleting dir >%s<.\n", pDir)
		}
	}

	// touch the root node with commit info
	_, err = etcdConn.Set(infoPath, string(jsonBytes), 0)
	if err != nil {
		log.Fatalf("error setting remoteRoot >%s<: %s\n", remoteRoot, err)
	}
	fmt.Printf("All done\n")
}
开发者ID:csigo,项目名称:config,代码行数:101,代码来源:main.go


注:本文中的github.com/coreos/go-etcd/etcd.Client.SetDir方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。