dockerize
dockerize copied to clipboard
Add arithmetic functions (extend current functionality)
What do you think about implementing some basic arithmetic functions. My suggestion would be something similar to https://github.com/hashicorp/consul-template/blob/de2ebf4/template_functions.go#L727-L901
OK w/ me. There was suggestion to add https://github.com/Masterminds/sprig in #44 which has math and many other funcs.
@jwilder https://github.com/Masterminds/sprig looks like a good suggestion. My current requirements would be covered.
The main question for me is how handle the overlapping in the functions. There are some duplicates in the function names (e.g. contains, default, add, lower, upper), in some cases with slightly different functionality. I can think of the following options:
- Add the sprig functions to the template after the current functions: this breaks backwards compatibility as the sprig functions overwrite the current functions.
- Add the sprig functions to the template before the current functions: not all sprig functions are available, in some cases the processing would seem awkward (function
addis provided by dockerize where all other arithmetic functions are provided by sprig). - Add the sprig functions with a prefix (sprig function
addwould becomesprig_addorsprigAdd)
In my opinion we should go for option 3 (which prefix variant should we take?).
What do you think?
@ludovicc @dbeckham: As it would solve #44 as well, what do you think?
Adding the sprig functions with prefix is probably the safest choice here.
Just added a first version of a PR for the sprig functions with prefix. What do you think. If we agree on this implementation, I will also update the README accordingly.
@jwilder With #61 being closed, I am not sure, how to proceed with my requirement for basic arithmetic. Any suggestions?
How about adding the the math functions directly to templates.go as you had suggested in the description?