-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
I wish there was a getv
equivalent that accepted a default value
#219
Comments
@larsks I wonder if we can do this on a way that backwards compatible. |
does |
@bacongobbler While that expression accomplishes the same thing, for someone coming from a different background where things like That linked patch looks like a step in the right direction, although it could use some documentation to go with it. |
@larsks that expression actually doesn't work; tried it myself today. However, with the proposed function it would look like |
@bacongobbler @larsks I wish go template function took optional params. Some people want thing to error if the key does not exist, some one a default value, some want a default empty value. I guess we could solve this with more template functions, or figure out new functions that take options. |
Alternatively, a function which returns an empty string instead of an error would allow us to take advantage of the builtin
That should minimize it down to 2 different functions while covering all use cases: one to return an empty string and one returning an error when the key does not exist. |
Highly desired feature from my part. Due to the limited scoping flexibility it's very hard to produce default values when dealing with single-line properties (such as some HAProxy configuration lines). |
Could adding a
Where |
Here's an example from Sprig. I'd be happy to port to Confd if others think this fits the bill: https://github.com/Masterminds/sprig/blob/master/functions.go#L44 https://github.com/Masterminds/sprig/blob/master/functions.go#L231 |
I don't have a particular preference for syntax, so whatever fits the convention is fine by me. The proposed |
👍 Any progress? |
👍 it's a bit confusing that the documetion mention this now, and the version 0.11.0 doesn't have it, |
@fruch I'd accept a PR to remove that documentation. |
Any progress? |
none. |
The documentation should be fixed since the default value is not available as described in the documentation. |
Fixed in 4388e4b |
My templates often end up being far too verbose because of things like this:
That makes it quite hard to visually parse the config files. Much easier would be something like:
The text was updated successfully, but these errors were encountered: