Add filename when exporting results as csv, fixes #75

This commit is contained in:
Dan Sosedoff 2015-01-05 19:46:02 -06:00
parent 0bb942857a
commit 165f411083

7
api.go
View File

@ -7,6 +7,7 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
@ -292,12 +293,12 @@ func API_HandleQuery(query string, c *gin.Context) {
q := c.Request.URL.Query() q := c.Request.URL.Query()
if len(q["format"]) > 0 { if len(q["format"]) > 0 && q["format"][0] == "csv" {
if q["format"][0] == "csv" { filename := fmt.Sprintf("pgweb-%v.csv", time.Now().Unix())
c.Writer.Header().Set("Content-disposition", "attachment;filename="+filename)
c.Data(200, "text/csv", result.CSV()) c.Data(200, "text/csv", result.CSV())
return return
} }
}
c.JSON(200, result) c.JSON(200, result)
} }