-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv.go
37 lines (32 loc) · 859 Bytes
/
csv.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
package leaderboard
import (
"os"
"github.com/gocarina/gocsv"
"github.com/pewpewlive/common-go/ppl_types"
)
// Utility to read `[]ppl_types.HofEntry` from csv file.
func GetScoresFromCSV(path string) ([]ppl_types.HofEntry, error) {
var scores []ppl_types.HofEntry
file, err := os.OpenFile(path, os.O_RDONLY, os.ModePerm)
if err != nil {
return scores, err
}
err = gocsv.UnmarshalFile(file, &scores)
if err != nil {
return scores, err
}
return scores, nil
}
// Utility to read `[]ppl_types.AccountInfo` from csv file.
func GetAccountsFromCSV(path string) ([]ppl_types.AccountInfo, error) {
var accounts []ppl_types.AccountInfo
file, err := os.OpenFile(path, os.O_RDONLY, os.ModePerm)
if err != nil {
return accounts, err
}
err = gocsv.UnmarshalFile(file, &accounts)
if err != nil {
return accounts, err
}
return accounts, nil
}