-
Notifications
You must be signed in to change notification settings - Fork 0
/
location.go
49 lines (37 loc) · 899 Bytes
/
location.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
package lib
import (
"fmt"
"os"
"os/user"
"runtime"
)
// os.Getenv seems to continue giving me goroutine issues
// hard setting HOME path. Please set your path accordingly
var homepath string = "/home/kaleb"
// Storage returns storage locations for configuration and static folders
func Storage() string {
if runtime.GOOS == "linux" {
// return fmt.Sprintf("%s/.config/persephone", os.Getenv("HOME"))
usr, _ := user.Current()
return fmt.Sprintf("%s/.config/persephone", usr.HomeDir)
}
return ""
}
// LocGet returns file location within bot's storage directory.
func LocGet(file string) string {
storage := Storage()
if storage != "" {
if fileExists(file) {
return file
}
return fmt.Sprintf("%s/%s", storage, file)
}
return file
}
func fileExists(file string) bool {
info, err := os.Stat(file)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}