-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
55 lines (45 loc) · 1.06 KB
/
util.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package gamedayapi
import (
"fmt"
"log"
"os/user"
"time"
)
const (
// GamedayHostname is the hostname of the MLB gameday site
GamedayHostname = "http://gd2.mlb.com"
// GamedayBaseURL is the base URL of the MLB gameday files
GamedayBaseURL = "http://gd2.mlb.com/components/game/mlb"
// GamedayBasePath is the base path of the MLB gameday files
GamedayBasePath = "/components/game/mlb"
)
// BaseCachePath returns the local directory where gameday files are cached.
func BaseCachePath() string {
return homeDir() + "/go-gameday-cache"
}
func datePath(date time.Time) string {
return fmt.Sprintf("/year_%02d/month_%02d/day_%02d", date.Year(), date.Month(), date.Day())
}
func dateURL(date time.Time) string {
return GamedayBaseURL + datePath(date)
}
func homeDir() string {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
return usr.HomeDir
}
func check(e error) {
if e != nil {
panic(e)
}
}
func appendIfMissing(slice []string, i string) []string {
for _, ele := range slice {
if ele == i {
return slice
}
}
return append(slice, i)
}