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

Add Go template support #36

Closed
hatifnatt opened this issue Feb 28, 2020 · 3 comments
Closed

Add Go template support #36

hatifnatt opened this issue Feb 28, 2020 · 3 comments

Comments

@hatifnatt
Copy link

Hello thanks for interesting alternative for confd. I think ability to have multiple backends is the 'killer feature'. Currently I need to have multiple Consul backends and in the future Vault will be added to the list but I would not want to be 'vendor locked' by using consul-template.

So I'm trying to switch from confd and during review of remco as candidate my main concern was different template engine. And after actually trying to adapt my templates from Go template to Django temple I can say that it takes a lot of effort. It took less than 2 hours to create new installation and configuration SaltStack formula for remco, but it took more than 4 hours to adapt simple Haproxy template from Go template to Django template.

Main problems with Django template:

  • no variables, {% with %} can help, but because it is require end tag it's not very elegant
  • very limited amount of filters, there is no basic replace filter like in Jinja2, nor index from Go template, of course there is workaround available out-of-the box with this JavaScript custom filters, but for such basic things you can expect built-in tools
  • JS filters feature add a lot of flexibility but it's not portable, you can't share your template without your custom filters, not a problem at first glance but limits widespread of the tool
  • JS filters does not throw any errors if they written incorrectly they just simply does not work. I created a deliberately incorrect code and did not receive any error.

And main problem, you can't just switch from confd with some fixes here and there, you need to fully rewrite your templates. I think if Go template became available more people will happily switch to remco because it's flexibility is really impressive.

I understand that adding another template engine is not a piece of cake and probably overly complicate this tool and even more likely, it’s completely not required for you personally. So I won't really expect that Go template will be added it's just my thoughts and experience of using remco.

@HeavyHorst
Copy link
Owner

Hello and thank you for your helpful feedback!

The problem that you can't just switch from confd is of course true.
I took a quick look and the template engine is really only used in this 2 files:

https://github.com/HeavyHorst/remco/blob/7c4b7a4d5faa65d3072515c395980b1cdfde8273/pkg/template/renderer.go
https://github.com/HeavyHorst/remco/blob/d8476160a206d43269ba34b46fb625726c2e0e82/pkg/template/template_filters.go

it shouldn't be too hard to add go templates as a second template language, and i will probably do it, especially to ease the transition from confd.

very limited amount of filters, there is no basic replace filter like in Jinja2, nor index from Go template, of course there is workaround available out-of-the box with this JavaScript custom filters, but for such basic things you can expect built-in tools

I am also open for adding more standard filters if needed.
Could you open issues for your needed filters?

@hatifnatt
Copy link
Author

More template engines - more thing to support. I.e. if you add custom filter (function in case of Go template) you need to add it to each engine where it missing from.
I'm glad that Go template will be probably added, although, it's actually missing even more things than Django template, with some basic custom functions like in confd it can be some kind of common denominator.
Of course, no problem I will open issues about the function I am missing.

@HeavyHorst
Copy link
Owner

I will stay with just pongo2 for now.
Let me know if you miss any filters/functions.

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

No branches or pull requests

2 participants