forked from taggledevel2/ratchet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv_writer.go
45 lines (37 loc) · 1.14 KB
/
csv_writer.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
package processors
import (
"io"
"github.com/tanapoln/ratchet/v2/data"
"github.com/tanapoln/ratchet/v2/util"
)
// CSVWriter is handles converting data.JSON objects into CSV format,
// and writing them to the given io.Writer. The Data
// must be a valid JSON object or a slice of valid JSON objects.
// If you already have Data formatted as a CSV string you can
// use an IoWriter instead.
type CSVWriter struct {
Parameters util.CSVParameters
}
// NewCSVWriter returns a new CSVWriter wrapping the given io.Writer object
func NewCSVWriter(w io.Writer) *CSVWriter {
writer := util.NewCSVWriter()
writer.SetWriter(w)
return &CSVWriter{
Parameters: util.CSVParameters{
Writer: writer,
WriteHeader: true,
HeaderWritten: false,
SendUpstream: false,
},
}
}
// ProcessData defers to util.CSVProcess
func (w *CSVWriter) ProcessData(d data.JSON, outputChan chan data.JSON, killChan chan error) {
util.CSVProcess(&w.Parameters, d, outputChan, killChan)
}
// Finish - see interface for documentation.
func (w *CSVWriter) Finish(outputChan chan data.JSON, killChan chan error) {
}
func (w *CSVWriter) String() string {
return "CSVWriter"
}