Skip to content

Commit

Permalink
added MapDir function for mapping out etcd directories
Browse files Browse the repository at this point in the history
  • Loading branch information
fritzy committed May 28, 2014
1 parent 3a20318 commit cd99c2a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions resource/template/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (t *TemplateResource) createStageFile() error {
tplFuncMap["Base"] = path.Base

tplFuncMap["GetDir"] = t.Dirs.Get
tplFuncMap["MapDir"] = mapNodes
tmpl := template.Must(template.New(path.Base(t.Src)).Funcs(tplFuncMap).ParseFiles(t.Src))
if err = tmpl.Execute(temp, t.Vars); err != nil {
return err
Expand Down
13 changes: 13 additions & 0 deletions resource/template/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"syscall"

"github.com/kelseyhightower/confd/log"
"github.com/coreos/go-etcd/etcd"
)

func appendPrefix(prefix string, keys []string) []string {
Expand All @@ -34,6 +35,18 @@ func cleanKeys(vars map[string]interface{}, prefix string) map[string]interface{
return clean
}

func mapNodes(node *etcd.Node) map[string]interface{} {
result := make(map[string]interface{})
for _, node := range node.Nodes {
if len(node.Nodes) > 0 {
result[node.Key] = node.Nodes
} else {
result[node.Key] = node.Value
}
}
return cleanKeys(result, node.Key)
}

// isFileExist reports whether path exits.
func isFileExist(fpath string) bool {
if _, err := os.Stat(fpath); os.IsNotExist(err) {
Expand Down

0 comments on commit cd99c2a

Please sign in to comment.