-
Notifications
You must be signed in to change notification settings - Fork 18.1k
proposal: text/template: allow template and block outputs to be chained #33273
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
This comment has been minimized.
This comment has been minimized.
Motivation: Azure/aks-engine#1663 |
/cc @robpike and @adg. I believe the Go 1.6 template blocks were meant to address this need, but maybe it is worth taking a second look to see how well it has done that. |
In the example provided in this issue, I don't see why the caller wouldn't do the gzipping and base64 encoding in plain Go. Is there some more context that I'm missing? In the aks-engine PR, I'm not seeing the connection. I also wonder why the author is using text/template to generate JSON; it seems easier and safer to me to use encoding/json. @sylr can you provide more context as to how these features would benefit you? |
@adg aks-engine use text/template to generate a yaml string which is used as value in a json object. Only parts of the YAML are gzipped, e.g.: Some times the template content is not coming from functions but are defined in the templates: Allowing to chain template and block output would allow to do gzipping directly in the template. |
I can see how the feature would be useful, but the proposed syntax doesn't make sense. The syntax for a
In the given example
the part that says
would be considered the |
Yes it would need to change how parameters are handled. It currently evaluates like this :
It would evaluate like this:
|
As far as I see things it is the current syntax that does not make sense. The 3rd parameter of the template statement is implicitly handled as a variadic argument which is confusing. |
The third argument to the template statement is not a variadic; it's a pipeline, which is just the text/template way of saying "expression". It's consistent with the rest of the grammar. Any change we make here would need to be compatible with the existing uses of text/template, so changing the meaning of the grammar there is a non-starter. |
Then what about a new type of block which takes an
|
To achieve that, you can define a function like 'eval' yourself. For example:
The trick is to make that function enclose the template variable itself, for example:
|
To summarize the discussion so far:
That is, the proposed feature can't be accepted with the suggested syntax, and the functionality can already be implemented with a short bit of Go code in the caller. Those two together make it sound like we should decline this proposal. Am I reading anything wrong? |
I am a bit sad this would not be not part of |
Based on the discussion, then, this seems like a likely decline. |
No change in consensus, so declined. |
Uh oh!
There was an error while loading. Please reload this page.
It would be nice to be able to post process the output of the
template
andblock
directives, e.g.:Regards.
The text was updated successfully, but these errors were encountered: