forked from erizocosmico/go-ics
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.go
More file actions
62 lines (54 loc) · 1004 Bytes
/
utils.go
File metadata and controls
62 lines (54 loc) · 1004 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ics
import (
"io/ioutil"
"net/http"
"os"
"regexp"
"strings"
)
const (
uts = "1136239445"
icsFormat = "20060102T150405Z"
icsFormatWholeDay = "20060102"
)
func downloadFromURL(url string) (string, error) {
response, err := http.Get(url)
if err != nil {
return "", err
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
return "", err
}
return string(contents), nil
}
func trimField(field, cutset string) string {
re, _ := regexp.Compile(cutset)
cutsetRem := re.ReplaceAllString(field, "")
return strings.TrimRight(cutsetRem, "\r\n")
}
func fileExists(fileName string) bool {
_, err := os.Stat(fileName)
return err == nil
}
func parseDayNameToIcsName(day string) string {
switch day {
case "Mon":
return "MO"
case "Tue":
return "TU"
case "Wed":
return "WE"
case "Thu":
return "TH"
case "Fri":
return "FR"
case "Sat":
return "ST"
case "Sun":
return "SU"
default:
return ""
}
}