-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcsv.go
More file actions
41 lines (31 loc) · 731 Bytes
/
csv.go
File metadata and controls
41 lines (31 loc) · 731 Bytes
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
package main
import (
"encoding/csv"
"os"
"strings"
)
type CSVRecord struct {
RFC string
Id string
Ambient string
}
func readCSV(csvFilepath string) map[string]CSVRecord {
csvfile, _ := os.Open(csvFilepath)
defer csvfile.Close()
reader := csv.NewReader(csvfile)
reader.FieldsPerRecord = -1
reader.Comma = ','
rawCSVdata, _ := reader.ReadAll()
db := make(map[string]CSVRecord)
var oneRecord CSVRecord
// var allRecords []CSVRecord
for _, each := range rawCSVdata {
oneRecord.RFC = strings.ToUpper(each[0])
oneRecord.Id = each[1]
oneRecord.Ambient = strings.ToUpper(each[2])
//allRecords = append(allRecords, oneRecord)
db[oneRecord.RFC] = oneRecord
}
// return allRecords
return db
}