In C# the IEnumerator interface would be used which would allow a caller to provide anything from an array, list or more exotic source of data (e.g. the contents of a TCP connection).
I have seen the io.Reader interface and I was hoping that someone could say if accepting an io.Reader is the most idiomatic golang way to accept data from as many data sources as possible with the minimum of fuss for the API users.
Clearly this interface is at the byte level and appropriate restrictions / conversion functions would be needed for non-byte data (e.g. uint32’s) if a byte-wise interface was used.
Alternatives that I have found are to create a potentially unique enumerator type of the form of one of the possibilities from the go cookbook [1] or to use an existing package such as go-enumerate [2] but I get the impression that is not particularly popular. Another choice would be to go for io.ReadSeeker as that would allow the read position to move on only if the object generation was successful, but this may restrict the caller design freedom.
The use case I have in mind is for a public API function that would read data from the source to generate an object it would return by consuming some of the data from the source and leave excess data unread for the next call of the public API.
If anyone has some insight into the most common choice for such an input data source argument type then I would be delighted if you could share it with me.
[1] https://github.com/kjk/go-cookbook/tree/master/3-ways-to-iterate
[2] https://github.com/swdyh/go-enumerable