forked from taggledevel2/ratchet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
csv_transformer.go
39 lines (33 loc) · 1.1 KB
/
csv_transformer.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
package processors
import (
"github.com/dailyburn/ratchet/data"
"github.com/dailyburn/ratchet/util"
)
// CSVTransformer converts data.JSON objects into a CSV string object
// and sends it on to the next stage. In use-cases where
// you simply want to write to a CSV file, use CSVWriter instead.
//
// CSVTransformer is for more complex use-cases where you need to
// generate CSV data and perhaps send it to multiple output stages.
type CSVTransformer struct {
Parameters util.CSVParameters
}
// NewCSVTransformer returns a new CSVTransformer wrapping the given io.Writer object
func NewCSVTransformer() *CSVTransformer {
return &CSVTransformer{
Parameters: util.CSVParameters{
Writer: util.NewCSVWriter(),
WriteHeader: true,
HeaderWritten: false,
SendUpstream: true,
},
}
}
func (w *CSVTransformer) ProcessData(d data.JSON, outputChan chan data.JSON, killChan chan error) {
util.CSVProcess(&w.Parameters, d, outputChan, killChan)
}
func (w *CSVTransformer) Finish(outputChan chan data.JSON, killChan chan error) {
}
func (w *CSVTransformer) String() string {
return "CSVTransformer"
}