golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123k stars 17.54k forks source link

text/template: Permit user of Reader objects in templates #37092

Open zaddok opened 4 years ago

zaddok commented 4 years ago

In the case where we need to use a reader to avoid buffering large amounts of data in memory, there appears no way to use this reader in a go template.

This issue was raised before here:

https://github.com/golang/go/issues/25160

In summary, it was dismissed on the basis of "most people don't need this". I would like to contest this. There are a lot of things "most people don't need" but what if the reason for the need is an important edge case (i.e. applications processing large data sets). Surely there are some people processing applications that operate over large data sets?

ianlancetaylor commented 4 years ago

I'm not sure what you are asking for. Issue #25160 ended by suggesting opening a proposal for the change. Do you want to do that? Indicate exactly what you think should be added to the text/template API. Thanks.

toothrot commented 4 years ago

@zaddok See also the discussion of the proposal at #29165. Unless some of the concerns there are addressed in this issue, I don't understand what change should be made to Go.

zaddok commented 4 years ago

At a high level, it would be good to not have to (for example) load a 10mb array into memory so that a template can range over it to build a html or text document (that may also end up being 10mb). It would be desirable if a template could range over a Reader object that returns elements one by one.

I am not so interested in prescribing a particular implementation, just trying to work out how to handle requests that trigger high memory usage in my app server.