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

proposal: Go 2: text/template: allow template and block outputs to be chained #33273

Open
sylr opened this issue Jul 25, 2019 · 5 comments

Comments

@sylr
Copy link

commented Jul 25, 2019

It would be nice to be able to post process the output of the template and block directives, e.g.:

{{ block "letter" . | GzipString | Base64EncodeString }}
Dear {{.Name}},
{{if .Attended}}It was a pleasure to see you at the wedding.
{{else}}It is a shame you couldn't make it to the wedding.{{end}}
{{with .Gift}}Thank you for the lovely {{.}}.
{{end}}
Best wishes,
Josie
{{ end }}
{{ define "letter" }}
Dear {{.Name}},
{{if .Attended}}It was a pleasure to see you at the wedding.
{{else}}It is a shame you couldn't make it to the wedding.{{end}}
{{with .Gift}}Thank you for the lovely {{.}}.
{{end}}
Best wishes,
Josie
{{ end }}
{{ template "letter" . | GzipString | Base64EncodeString }}

Regards.

@gopherbot gopherbot added this to the Proposal milestone Jul 25, 2019

@gopherbot gopherbot added the Proposal label Jul 25, 2019

@alersenkevich

This comment was marked as spam.

Copy link

commented Jul 25, 2019

Bad. Disrespect

@sylr

This comment has been minimized.

Copy link
Author

commented Jul 29, 2019

Motivation: Azure/aks-engine#1663

@rsc

This comment has been minimized.

Copy link
Contributor

commented Aug 27, 2019

/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.

@adg

This comment has been minimized.

Copy link
Contributor

commented Sep 2, 2019

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?

@ianlancetaylor ianlancetaylor changed the title proposal: Go 2: text/template allow template and block outputs to be chained proposal: Go 2: text/template: allow template and block outputs to be chained Sep 3, 2019

@sylr

This comment has been minimized.

Copy link
Author

commented Sep 13, 2019

@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.:

https://github.com/Azure/aks-engine/blob/master/parts/k8s/cloud-init/nodecustomdata.yml#L6-L9

Some times the template content is not coming from functions but are defined in the templates:

https://github.com/Azure/aks-engine/blob/master/parts/k8s/cloud-init/nodecustomdata.yml#L245-L261

Allowing to chain template and block output would allow to do gzipping directly in the template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.