hoverfly icon indicating copy to clipboard operation
hoverfly copied to clipboard

Pongo2 as templating engine

Open petkostas opened this issue 3 years ago • 9 comments

The template engine used by Hoverfly looks stale (Raymond) I would propose to consider porting Pongo2 as the template engine of choice. Pongo2 is active, has similar approach to Raymond but includes more features

petkostas avatar Sep 10 '22 08:09 petkostas

Thanks @petkostas. Will take a look this week.

tommysitu avatar Sep 12 '22 10:09 tommysitu

looks promising. As long as it supports handlebars for backward compatibility, and is fast (because hoverfly is used for load testing in many places), it's worth a try.

tommysitu avatar Sep 14 '22 21:09 tommysitu

This should cover the requirements for Hoverfly https://pkg.go.dev/github.com/flosch/pongo2#RegisterFilter Might require a few changes here and there, but we could also introduce helper methods, allowing the registration of extensions (tags/filters, etc) dynamically, without having to wait for a new release of the project. Regarding performance, we need to check, yet I believe, as it's more maintained and adopted that should match Raymond. In the case there are incpompatibilies, a flag could be introduced to switch template engine over the other, similar to how Django supports them

petkostas avatar Sep 15 '22 18:09 petkostas

Also as I mentioned, I am fairly new to GO so I am not really aware of all the alternatives, if there is something else more promising feel free to drop it here, I can possibly provide some context after 10+ years of working with Jinja and Django templates.

petkostas avatar Sep 15 '22 18:09 petkostas

Hi @tommysitu I have a very weird case when JSON is a value of an attribute of some XML which in its turn a property value of a JSON e.g.

{
  "prop": "<table baz=\"{&quot;version&quot;:1}\">Foo</table>"
}

And I wonder if it's possible to access version property of the innermost JSON using current templates (Raymond) or any other future templating mechanism.

moikot avatar Oct 27 '22 20:10 moikot

@tommysitu someone has done benchmarking on go templates engine and it seems pongo2 is much faster than raymonds(named as handlebars in the link). You can check below github link for benchmarking results. If it seems promising, then probably, we can keep both for a while by taking the option from the user to use and then deprecate it other one after sometime.

https://github.com/SlinSo/goTemplateBenchmark#full-featured-template-engines-1 https://github.com/SlinSo/goTemplateBenchmark

kapishmalik avatar Jan 04 '23 08:01 kapishmalik

@petkostas Is there a way in pongo2 to access context in the filter functions?

Secondly, can we do a method call as {{<method name> <args1> <args2>}}. I see that method can be called via {{method(arg1,arg2)}}. I could not find these two in their documentation. These are required for backward compatibility.

kapishmalik avatar Jan 05 '23 07:01 kapishmalik

@kapishmalik not sure for this, as I have not personally used pongo2 (but rather Django) for the first question, it should be available (context). I will try to find some time and do some tests with it and get back

petkostas avatar Jan 11 '23 08:01 petkostas