-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv.go
More file actions
74 lines (65 loc) · 1.42 KB
/
csv.go
File metadata and controls
74 lines (65 loc) · 1.42 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"encoding/csv"
"fmt"
"log"
"os"
"strconv"
)
/*
Read a simple CSV file and raise an error if any issues
*/
func readCsvFile(filePath string) [][]string {
f, err := os.Open(filePath)
if err != nil {
log.Fatal("Unable to read input file "+filePath, err)
}
defer f.Close()
csvReader := csv.NewReader(f)
records, err := csvReader.ReadAll()
if err != nil {
log.Fatal("Unable to parse file as CSV for "+filePath, err)
}
return records
}
func processCsvFile(records *[][]string) map[int]record {
var recordsMap = make(map[int]record)
rec := *records
for i := 0; i < len(rec); i++ {
id, _ := strconv.Atoi(rec[i][0])
var r = record{
trackId: id,
albumId: rec[i][1],
title: rec[i][2],
}
recordsMap[r.trackId] = r
}
return recordsMap
}
type record struct {
trackId int
albumId string
title string
}
func main() {
var s string = "Data test "
var sRef = &s // This is a memory address
var t = *sRef
fmt.Println("Record: ", sRef, t)
//records := readCsvFile("data/tracks.csv")
//var allRecordsMap = processCsvFile(&records)
//
//for _, rec := range allRecordsMap {
// //filter our all records: between [100-200]
// //if rec.trackId >= 100 && rec.trackId <= 200 {
// // fmt.Println("Record: ", rec)
// //}
// matched, err := regexp.Match(`Two.*`, []byte(rec.title))
// if err != nil {
// log.Fatal(err)
// }
// if matched {
// fmt.Println("Record: ", rec)
// }
//}
}