本文整理汇总了Golang中github.com/coreos/go-etcd/etcd.Client.DeleteDir方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.DeleteDir方法的具体用法?Golang Client.DeleteDir怎么用?Golang Client.DeleteDir使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/coreos/go-etcd/etcd.Client
的用法示例。
在下文中一共展示了Client.DeleteDir方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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")
}