-
Notifications
You must be signed in to change notification settings - Fork 152
/
dialect.go
51 lines (43 loc) · 1.24 KB
/
dialect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package csv
import (
"fmt"
"mime"
"net/http"
"github.com/influxdata/flux"
)
const DialectType = "csv"
// AddDialectMappings adds the influxql specific dialect mappings.
func AddDialectMappings(mappings flux.DialectMappings) error {
return mappings.Add(DialectType, func() flux.Dialect {
return &Dialect{
ResultEncoderConfig: DefaultEncoderConfig(),
}
})
}
// Dialect describes the output format of queries in CSV.
type Dialect struct {
ResultEncoderConfig
}
func (d Dialect) SetHeaders(w http.ResponseWriter) {
w.Header().Set("Content-Type", "text/csv; charset=utf-8")
w.Header().Set("Transfer-Encoding", "chunked")
if d.ResultEncoderConfig.AttachmentFilename != "" {
mediatype := "attachment"
params := map[string]string{
"filename": d.ResultEncoderConfig.AttachmentFilename,
"filename*": fmt.Sprintf("UTF-8''%s", d.ResultEncoderConfig.AttachmentFilename),
}
w.Header().Set("Content-Disposition", mime.FormatMediaType(mediatype, params))
}
}
func (d Dialect) Encoder() flux.MultiResultEncoder {
return NewMultiResultEncoder(d.ResultEncoderConfig)
}
func (d Dialect) DialectType() flux.DialectType {
return DialectType
}
func DefaultDialect() *Dialect {
return &Dialect{
ResultEncoderConfig: DefaultEncoderConfig(),
}
}