-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.go
46 lines (38 loc) · 934 Bytes
/
parser.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
package main
import (
"github.com/alexflint/go-arg"
"github.com/pgilad/jtl-parse/jtl"
"github.com/pgilad/jtl-parse/output"
)
const DefaultOutputFormat = "json"
type OutputType string
const (
CSV OutputType = "csv"
XML OutputType = "xml"
JSON OutputType = "json"
)
func main() {
var args struct {
Filename string `arg:"positional,required"`
Output string `arg:"-o" help:"specify the output type, valid options: csv,xml,json"`
}
args.Output = DefaultOutputFormat
arg.MustParse(&args)
outputType := OutputType(args.Output)
outputStream := getOutputStream(outputType)
data := make(chan interface{})
go jtl.Decode(args.Filename, data)
outputStream(data)
}
func getOutputStream(outputType OutputType) func(data <-chan interface{}) {
switch outputType {
case CSV:
return output.CSV
case XML:
return output.XML
case JSON:
return output.JSON
default:
panic("Unknown output type " + outputType)
}
}