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
text/template: The ability to output an io.Reader #25160
Comments
Why not use a func in the template like ioutil.ReadAll? |
ioutil.ReadAll would require me to buffer all of the stream before outputting it. I'm looking for the ability to output parts of the stream, one after the other, like io.Copy. |
The ioutil.ReadAll solution is probably fine for most users, so it's okay to close this issue. That being said, having a more traditional looping construct would open up the template package to more stream-like use-cases. Right now, the range directive is restricted to iterable types. |
Please feel free to open a proposal for your feature question per https://golang.org/s/proposal |
Change https://golang.org/cl/153339 mentions this issue: |
Having the ability to templatize and concatenate multiple streams through a template would be highly useful. One can think of this as a generalization of the functionality provided by MultiReader, TeeReader, etc, except we'd have the ability to store stubs in files, and have more granular control of intermediate text and formatting.
For example, I'd like to be able to write something similar to the following:
Currently, I have a workaround using channels, however the overhead of channel communication doesn't make it worth using.
The text was updated successfully, but these errors were encountered: