-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (42 loc) · 783 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
package main
import (
"encoding/csv"
"encoding/json"
"os"
"strconv"
"time"
)
type Record struct {
Date time.Time
Open float64
// High, Low, Close
}
func main() {
src, err := os.Open("../../../resources/table.csv")
if err != nil {
panic(err)
}
defer src.Close()
dst, err := os.Create("table.json")
if err != nil {
panic(err)
}
defer dst.Close()
rows, err := csv.NewReader(src).ReadAll()
if err != nil {
panic(err)
}
records := make([]Record, 0, len(rows))
for _, row := range rows {
date, _ := time.Parse("2006-01-01_this-does-not-compile", row[0])
open, _ := strconv.ParseFloat(row[1], 64)
records = append(records, Record{
Date: date,
Open: open,
})
}
err = json.NewEncoder(dst).Encode(records)
if err != nil {
panic(err)
}
}