我go-swagger
用来下载附件。这些是小的多行文件,另一端只有一个浏览器。我尝试将响应定义为'string'
,但找不到用多行文本填充有效负载的方法,它以“\r\n”而不是换行符到达。我也尝试了'string'
format 'binary'
,但随后客户端看到一个包含Reader{}
. 我yaml
的 200 响应内容如下所示:
headers:
Content-Disposition:
type: string
pattern: attachment; filename="attachement.txt"
Content-Type:
type: string
pattern: application/octet-stream
schema:
type: string
我也尝试了'string'
format 'byte'
,但我不想要base64
编码响应。对此有何建议?
这是我到目前为止所尝试的:
尝试“字符串”格式“字节”...
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
尝试“字符串”
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
尝试“字符串”格式“二进制”
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{}