Closed duckbrain closed 3 weeks ago
That makes sense, a couple of thoughts: We'd have to make sure the documentation makes it clear that the generated code supports this alternative. Maybe the generated comment could indicate that this is the case. In the high level implementation above should we use a sync.Once
to initialize the pipe in a way that is goroutine safe? We also might want to update the upload_download example to illustrate the use of SkipResponseWriter
.
I went to update the upload_download
example, then I realized it already will use this new code path, since it's returning an *os.File
for the io.ReadCloser
implementation. :smile:
I could contrive an alternative example that reads a file line by line and streams JSON for each line with line length, etc.
Oh that makes sense! nothing to do then, don't think it's worth coming up with a contrive example - thank you for looking into it!
When a server uses
SkipResponseBodyEncodeDecode
, the response must be of the typeio.ReadCloser
. In most cases I've come across, anio.Writer
would be more ergonomic to use. I often find myself needing to useio.Pipe
to create anio.Reader
I can write to. It's made worse by the fact that it's abstracting thehttp.ResponseWriter
and pushing it through abufio.Reader
, so there's lots of extra copying going on.I propose to have the generated code check if the
io.ReadCloser
implementsio.WriterTo
, and if it does, call that instead.Additionally, it'd be nice to have a helper in the goa package to implement the interface from an
io.WriterTo
, to make it easier to switch to, eg: If used as the response to a handler, theRead
would never be called, and the pipe would never be created.As an alternate suggestion, you could have some way in the DSL that changes the expected type.