Skip to content
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 from
Closed

JSON parsing functions #101

wants to merge 4 commits into from

Conversation

andymuldowney
Copy link

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
Copy link
Owner

Very nice!

@kelseyhightower
Copy link
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.

@carmstrong
Copy link
Collaborator

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

@carmstrong
Copy link
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'

@kelseyhightower
Copy link
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

@kelseyhightower
Copy link
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.

@chrisjenx
Copy link

Could someone add an example to the docs for this?

seewerah pushed a commit to seewerah/confd that referenced this pull request Sep 21, 2024
)

Bumps [github.com/sirupsen/logrus](https://github.com/sirupsen/logrus) from 1.8.1 to 1.9.0.
- [Release notes](https://github.com/sirupsen/logrus/releases)
- [Changelog](https://github.com/sirupsen/logrus/blob/master/CHANGELOG.md)
- [Commits](sirupsen/logrus@v1.8.1...v1.9.0)

---
updated-dependencies:
- dependency-name: github.com/sirupsen/logrus
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants