-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbands.go
50 lines (44 loc) · 950 Bytes
/
bands.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
package main
import (
"encoding/json"
"os"
"sort"
"time"
)
type BandInternal struct {
Date string `json:"date"`
Time string `json:"time"`
Band string `json:"band"`
Stage string `json:"stage"`
}
type Band struct {
Date time.Time
Name string
Stage string
}
func load() ([]Band, error) {
data, err := os.ReadFile("data.json")
if err != nil {
return nil, err
}
bandsInternal := make([]BandInternal, 0)
if err := json.Unmarshal(data, &bandsInternal); err != nil {
return nil, err
}
bands := make([]Band, len(bandsInternal))
for i, bandInternal := range bandsInternal {
date, err := time.Parse("02/01/2006 15:04 MST", bandInternal.Date+" "+bandInternal.Time+" CEST")
if err != nil {
return nil, err
}
bands[i] = Band{
Date: date,
Name: bandInternal.Band,
Stage: bandInternal.Stage,
}
}
sort.Slice(bands, func(i, j int) bool {
return bands[i].Date.Before(bands[j].Date)
})
return bands, nil
}