Conversation
|
Looks like there are some issues with templates halting execution when eg. iterating over nil ranges. So, no matter what, it doesn't seem like adding a Resolver interface magically lets us customize execution. Kinda writing off this idea but will keep this open for discussion. edit: It's possible to get around this by creating a type which implements |
| } | ||
|
|
||
| func (t *Template) Runtime() *Runtime { | ||
| st := pool_State.Get().(*Runtime) |
There was a problem hiding this comment.
This will give you any runtime from the pool, possibly a new one, not the one executing the template.
There was a problem hiding this comment.
Instead, you should create a runtime, then create a custom resolver to which you pass the runtime, then set the resolver in the runtime, then execute the template.
|
I like the overall idea, however I believe it would be good to give users a way to hook and redirect variable declarations as well in order to make a custom resolver really useful. I'm picturing something like a user defined and controlled |
Opening a PR with a prototype as a means to discuss custom resolvers. Based off of this comment in #110, custom resolvers allow us to override default functionality when executing a template. This would open the possibility to:
This PR is purely a concept. It has no tests, and it exposes *Runtime directly from a template, which I do not like. So, word of warning, this PR is not ready and the aim here is to open a discussion with maintainers and owners regarding whether Resolver interfaces can be considered.
Stealing from my previous comment:
It adds a single interface -
Resolver:This allows us to define custom functions overriding default functionality in Resolve. You can always get the default resolver functionality within Runtime by calling
runtime.DefaultResolver().Usage:
I don't like how I have to expose the
Runtime()func within templates to get the default resolver at all to be honest, but yeah, like I said - it's a hacky POC to show that interfaces here might help.