-
Notifications
You must be signed in to change notification settings - Fork 6
/
csv_writer.go
45 lines (37 loc) · 1.18 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/teambenny/goetl/etldata"
"github.com/teambenny/goetl/etlutil"
)
// CSVWriter is handles converting etldata.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 etlutil.CSVParameters
}
// NewCSVWriter returns a new CSVWriter wrapping the given io.Writer object
func NewCSVWriter(w io.Writer) *CSVWriter {
writer := etlutil.NewCSVWriter()
writer.SetWriter(w)
return &CSVWriter{
Parameters: etlutil.CSVParameters{
Writer: writer,
WriteHeader: true,
HeaderWritten: false,
SendUpstream: false,
},
}
}
// ProcessData defers to etlutil.CSVProcess
func (w *CSVWriter) ProcessData(d etldata.Payload, outputChan chan etldata.Payload, killChan chan error) {
etlutil.CSVProcess(&w.Parameters, d, outputChan, killChan)
}
// Finish - see interface for documentation.
func (w *CSVWriter) Finish(outputChan chan etldata.Payload, killChan chan error) {
}
func (w *CSVWriter) String() string {
return "CSVWriter"
}