Skip to content

Commit

Permalink
Add new ls and lsdir methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kelseyhightower committed Aug 10, 2014
1 parent d82602d commit 8cf5a2f
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 10 deletions.
5 changes: 1 addition & 4 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Godeps/_workspace/src/github.com/kelseyhightower/memkv/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 24 additions & 4 deletions docs/templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Alias for the path.Base function.

### get

Returns the KVPair where key matches its argument.
Returns the KVPair where key matches its argument. Returns an error if key is not found.

```
{{with get "/key"}}
Expand All @@ -31,7 +31,7 @@ Returns the KVPair where key matches its argument.

### gets

Returns all KVPair, []KVPair, where key matches its argument.
Returns all KVPair, []KVPair, where key matches its argument. Returns an error if key is not found.

```
{{range gets "/*"}}
Expand All @@ -42,22 +42,42 @@ Returns all KVPair, []KVPair, where key matches its argument.

### getv

Returns the value as a string where key matches its argument.
Returns the value as a string where key matches its argument. Returns an error if key is not found.

```
value: {{getv "/key"}}
```

### getvs

Returns all values, []string, where key matches its argument.
Returns all values, []string, where key matches its argument. Returns an error if key is not found.

```
{{range getvs "/*"}}
value: {{.}}
{{end}}
```

### ls

Returns all subkeys, []string, where path matches its argument. Returns an empty list if path is not found.

```
{{range ls "/deis/services"}}
value: {{.}}
{{end}}
```

### lsdir

Returns all subkeys, []string, where path matches its argument. It only returns subkeys that also have subkeys. Returns an empty list if path is not found.

```
{{range lsdir "/deis/services"}}
value: {{.}}
{{end}}
```

## Example Usage

```Bash
Expand Down
6 changes: 4 additions & 2 deletions resource/template/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,16 @@ func (t *TemplateResource) createStageFile() error {
// Add template functions
tplFuncMap := make(template.FuncMap)
tplFuncMap["base"] = path.Base
tplFuncMap["parent"] = path.Dir
tplFuncMap["sibling"] = t.GetSibling
tplFuncMap["ls"] = t.store.List
tplFuncMap["lsdir"] = t.store.ListDir
tplFuncMap["get"] = t.store.Get
tplFuncMap["gets"] = t.store.GetAll
tplFuncMap["getv"] = t.store.GetValue
tplFuncMap["getvs"] = t.store.GetAllValues
tplFuncMap["json"] = t.UnmarshalJsonObject
tplFuncMap["jsonArray"] = t.UnmarshalJsonArray
tplFuncMap["sibling"] = t.GetSibling
tplFuncMap["parent"] = path.Dir

tmpl := template.Must(template.New(path.Base(t.Src)).Funcs(tplFuncMap).ParseFiles(t.Src))
if err = tmpl.Execute(temp, nil); err != nil {
Expand Down

0 comments on commit 8cf5a2f

Please sign in to comment.