-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.go
61 lines (53 loc) · 1.33 KB
/
main.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
52
53
54
55
56
57
58
59
60
61
package main
import (
"flag"
"fmt"
"io"
"io/ioutil"
"os"
"github.com/karrick/goavro"
)
func main() {
compressionName := flag.String("compression", "null", "compression codec ('null', 'deflate', 'snappy'; default: 'null')")
flag.Parse()
schemaBytes, err := ioutil.ReadFile("../../fixtures/weather.avsc")
if err != nil {
bail(err)
}
fh, err := os.Create("weather.avro")
if err != nil {
bail(err)
}
defer func(ioc io.Closer) {
if err := ioc.Close(); err != nil {
bail(err)
}
}(fh)
ocfw, err := goavro.NewOCFWriter(goavro.OCFConfig{
W: fh,
Schema: string(schemaBytes),
CompressionName: *compressionName,
})
if err != nil {
bail(err)
}
err = ocfw.Append([]interface{}{
map[string]interface{}{"station": "011990-99999", "time": -619524000000, "temp": 0},
map[string]interface{}{"station": "011990-99999", "time": -619506000000, "temp": 22},
})
if err != nil {
bail(err)
}
err = ocfw.Append([]interface{}{
map[string]interface{}{"station": "011990-99999", "time": -619484400000, "temp": -11},
map[string]interface{}{"station": "012650-99999", "time": -655531200000, "temp": 111},
map[string]interface{}{"station": "012650-99999", "time": -655509600000, "temp": 78},
})
if err != nil {
bail(err)
}
}
func bail(err error) {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}