New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON parsing functions #101

Closed
wants to merge 4 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@andymuldowney

andymuldowney commented Jul 11, 2014

We use confd with etcd. In etcd, we often store values in JSON. We added two very basic mapped functions to the template parser that allows use to handle JSON values inside of templates - one for objects, and one for arrays.

Usage example:

{{with $c := JsonUnmarshalObject $container.Value}}
  {{printf "%s:%.0f" $c.ip $c.ports.web}};
{{end}}
@kelseyhightower

This comment has been minimized.

Show comment
Hide comment
@kelseyhightower

kelseyhightower Jul 14, 2014

Owner

Very nice!

Owner

kelseyhightower commented Jul 14, 2014

Very nice!

@kelseyhightower

This comment has been minimized.

Show comment
Hide comment
@kelseyhightower

kelseyhightower Jul 22, 2014

Owner

Thanks for the PR, I'm be speaking at events related to OSCON, and I'll get a chance to review this later in the week.

Owner

kelseyhightower commented Jul 22, 2014

Thanks for the PR, I'm be speaking at events related to OSCON, and I'll get a chance to review this later in the week.

@carmstrong

This comment has been minimized.

Show comment
Hide comment
@carmstrong

carmstrong Jul 30, 2014

Collaborator

Awesome! Could we add these to the template functions documentation?

Collaborator

carmstrong commented Jul 30, 2014

Awesome! Could we add these to the template functions documentation?

@carmstrong

This comment has been minimized.

Show comment
Hide comment
@carmstrong

carmstrong Aug 1, 2014

Collaborator

This is working great for me:

core@deis-1 ~ $ cat templates/something.conf.tmpl
BROKER_URL = 'redis://{{ with $obj := JsonUnmarshalObject .deis_locks_cache }}{{ printf "%s:%s" $obj.host $obj.port }}{{ end }}/0'
core@deis-1 ~ $ ./confd -onetime -config-file=/home/core/confd.toml
2014-08-01T04:49:18Z deis-1 ./confd[964]: INFO Target config /home/core/something.conf out of sync
2014-08-01T04:49:18Z deis-1 ./confd[964]: INFO Target config /home/core/something.conf has been updated
core@deis-1 ~ $ cat something.conf
BROKER_URL = 'redis://172.17.8.100:6379/0'
Collaborator

carmstrong commented Aug 1, 2014

This is working great for me:

core@deis-1 ~ $ cat templates/something.conf.tmpl
BROKER_URL = 'redis://{{ with $obj := JsonUnmarshalObject .deis_locks_cache }}{{ printf "%s:%s" $obj.host $obj.port }}{{ end }}/0'
core@deis-1 ~ $ ./confd -onetime -config-file=/home/core/confd.toml
2014-08-01T04:49:18Z deis-1 ./confd[964]: INFO Target config /home/core/something.conf out of sync
2014-08-01T04:49:18Z deis-1 ./confd[964]: INFO Target config /home/core/something.conf has been updated
core@deis-1 ~ $ cat something.conf
BROKER_URL = 'redis://172.17.8.100:6379/0'
@kelseyhightower

This comment has been minimized.

Show comment
Hide comment
@kelseyhightower

kelseyhightower Aug 4, 2014

Owner

Ok we have a few of these PRs that add json functions. We should merge them up into a single PR and add them 0.5.x and 0.6.x

Owner

kelseyhightower commented Aug 4, 2014

Ok we have a few of these PRs that add json functions. We should merge them up into a single PR and add them 0.5.x and 0.6.x

@kelseyhightower

This comment has been minimized.

Show comment
Hide comment
@kelseyhightower

kelseyhightower Aug 4, 2014

Owner

@andymuldowney @carmstrong I'm going to merge #111 once tests pass and update the docs. Closing this out, lets collaborate on #111 for JSON support.

Owner

kelseyhightower commented Aug 4, 2014

@andymuldowney @carmstrong I'm going to merge #111 once tests pass and update the docs. Closing this out, lets collaborate on #111 for JSON support.

@chrisjenx

This comment has been minimized.

Show comment
Hide comment
@chrisjenx

chrisjenx Oct 8, 2014

Could someone add an example to the docs for this?

chrisjenx commented Oct 8, 2014

Could someone add an example to the docs for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment