Set a correct content type header for CSV endpoint
This commit is contained in:
2
api.go
2
api.go
@@ -138,7 +138,7 @@ func API_HandleQuery(query string, c *gin.Context) {
|
|||||||
|
|
||||||
if len(q["format"]) > 0 {
|
if len(q["format"]) > 0 {
|
||||||
if q["format"][0] == "csv" {
|
if q["format"][0] == "csv" {
|
||||||
c.String(200, result.CSV())
|
c.Data(200, "text/csv", result.CSV())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ func (res *Result) Format() []map[string]interface{} {
|
|||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
func (res *Result) CSV() string {
|
func (res *Result) CSV() []byte {
|
||||||
buff := &bytes.Buffer{}
|
buff := &bytes.Buffer{}
|
||||||
writer := csv.NewWriter(buff)
|
writer := csv.NewWriter(buff)
|
||||||
|
|
||||||
@@ -189,5 +189,5 @@ func (res *Result) CSV() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
writer.Flush()
|
writer.Flush()
|
||||||
return buff.String()
|
return buff.Bytes()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user