-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparser.go
More file actions
66 lines (51 loc) · 1.1 KB
/
Copy pathparser.go
File metadata and controls
66 lines (51 loc) · 1.1 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
package main
import (
"encoding/csv"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strconv"
)
func parseCampaignCSV(filepath string) error {
f, err := os.Open(filepath)
if err != nil {
return err
}
defer f.Close()
r := csv.NewReader(f)
records, err := r.ReadAll()
campaigns = []campaign{}
for _, record := range records {
campaigns = append(campaigns, campaign{
campaignID: record[0],
marketID: record[1],
})
}
maxCampaign = getMaxCampaign(campaigns)
fmt.Println(maxCampaign)
return nil
}
func getMaxCampaign(campaigns []campaign) (max int) {
max, _ = strconv.Atoi(campaigns[0].campaignID)
for _, c := range campaigns[1:] {
cid, _ := strconv.Atoi(c.campaignID)
if cid > max {
max = cid
}
}
return
}
func parseshortURLsJSON(filepath string) error {
file, _ := ioutil.ReadFile(filepath)
_ = json.Unmarshal([]byte(file), &data)
return nil
}
func parseUsedCodesJSON(filepath string) error {
file, _ := ioutil.ReadFile(filepath)
err := json.Unmarshal([]byte(file), &usedCodesData)
if err != nil {
logFile.WriteString("ERROR " + err.Error() + "\n")
}
return nil
}