Skip to content

Instantly share code, notes, and snippets.

@popsikle
Last active August 29, 2015 14:14
Show Gist options
  • Save popsikle/54196d2e88ef934dd384 to your computer and use it in GitHub Desktop.
Save popsikle/54196d2e88ef934dd384 to your computer and use it in GitHub Desktop.
confd template help

Accounts is a nested json array:

{
  "id": "accounts",
  "dev": {
    "postgres": {
      "write": [
        {
          "user": "pgwrite",
          "pass": "pgwrite"
        }
      ],
      "read": [
        {
          "user": "pgread",
          "pass": "pgread"
        }
      ],
      "superuser": [
        {
          "user": "postgres",
          "pass": "postgres"
        }
      ]
    }
  }
}

This is the template functions:

{{$data := getenv "ACCOUNTS"}}
{{$accounts := json $data}}
{{$write := $accounts.dev.postgres.write}}

Accounts:
{{$accounts}}

Write:
{{$write}}

This is the template output:

Accounts:
map[id:accounts dev:map[postgres:map[write:[map[user:pgwrite pass:pgwrite]] read:[map[user:pgread pass:pgread]] superuser:[map[user:postgres pass:postgres]]]]]

Write:
[map[user:pgwrite pass:pgwrite]]

When I try to do anything with the $write variable, this is what I get:

2015-01-23T23:29:50Z e66c69f498ab confd[190]: WARNING Skipping confd config file.
2015-01-23T23:29:50Z e66c69f498ab confd[190]: ERROR template: app_override.tmpl:13:8: executing "app_override.tmpl" at <$write.user>: can't evaluate field user in type []interface {}

Things I have tried:

$write.user

{{with $write}}
    key: {{.Key}}
    value: {{.Value}}
{{end}}

$write[user]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment