From bf2df4e74f875e1aa3faa392ddde1fc3bcbf6698 Mon Sep 17 00:00:00 2001 From: Dan Sosedoff Date: Sat, 18 Oct 2014 08:15:13 -0700 Subject: [PATCH] Set a correct content type header for CSV endpoint --- api.go | 2 +- client.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/api.go b/api.go index 6a24fe5..1c56404 100644 --- a/api.go +++ b/api.go @@ -138,7 +138,7 @@ func API_HandleQuery(query string, c *gin.Context) { if len(q["format"]) > 0 { if q["format"][0] == "csv" { - c.String(200, result.CSV()) + c.Data(200, "text/csv", result.CSV()) return } } diff --git a/client.go b/client.go index 42b06df..1dc55ac 100644 --- a/client.go +++ b/client.go @@ -163,7 +163,7 @@ func (res *Result) Format() []map[string]interface{} { return items } -func (res *Result) CSV() string { +func (res *Result) CSV() []byte { buff := &bytes.Buffer{} writer := csv.NewWriter(buff) @@ -189,5 +189,5 @@ func (res *Result) CSV() string { } writer.Flush() - return buff.String() + return buff.Bytes() }