-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
52 lines (39 loc) · 929 Bytes
/
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
package main
import (
"context"
"log"
"time"
"golang.org/x/sync/errgroup"
)
var (
historicalJSONFilePath = "./data/historical.json"
currentJSONFilePath = "./data/current.json"
historicalCSVFilePath = "./data/historical.csv"
currentCSVFilePath = "./data/current.csv"
)
func getData(ctx context.Context, db *database) error {
g, ctx := errgroup.WithContext(ctx)
g.Go(func() error {
return getHistoricalData(ctx, db, historicalCSVFilePath)
})
g.Go(func() error {
return getCurrentData(ctx, db, currentCSVFilePath)
})
return g.Wait()
}
func main() {
log.SetFlags(log.Llongfile)
t := newTimer("setting up sqlite database")
db, err := newDatabase()
if err != nil {
log.Fatal(err)
}
t.end().reset("getting all the data")
defer t.end()
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()
err = getData(ctx, db)
if err != nil {
log.Fatal(err)
}
}