I am using go-swagger
to download attachments. These are small multi-line files, and there is just a browser on the other end.
I tried defining the response as 'string'
, but can find no way to populate the payload with multiline text, it arrives with "\r\n" instead of newlines. I also tried 'string'
format 'binary'
, but then the client sees a response containing a Reader{}
. My content yaml
for the 200 response looks like this:
headers:
Content-Disposition:
type: string
pattern: attachment; filename="attachement.txt"
Content-Type:
type: string
pattern: application/octet-stream
schema:
type: string
I also tried 'string'
format 'byte'
, but I don't want a base64
encoded response.
Any advice on this?
This is what I have tried so far:
trying "string" format "byte"...
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(payload)
// fails.. will not accept payload other than strfmt.Bas64
trying "string"
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(payload.String())
// accepts payload, but 13/10 get converted into \r\n
trying "string" format "binary"
type nopCloser struct {
io.Reader
}
func (nopCloser) Close() error { return nil }
payload := bytes.NewBufferString("first line")
payload.WriteByte(13)
payload.WriteByte(10)
payload.WriteString("second line")
payload.WriteByte(13)
payload.WriteByte(10)
resp := responses.NewGetResponseInfoOK()
resp.SetPayload(nopCloser(payload))
// accepts payload, but the browser sees a Reader{}