forked from fossabot/clash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.go
50 lines (40 loc) · 799 Bytes
/
path.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
package constant
import (
"os"
"os/user"
P "path"
)
const Name = "clash"
// Path is used to get the configuration path
var Path *path
type path struct {
homedir string
}
func init() {
currentUser, err := user.Current()
var homedir string
if err != nil {
dir := os.Getenv("HOME")
if dir == "" {
dir, _ = os.Getwd()
}
homedir = dir
} else {
homedir = currentUser.HomeDir
}
homedir = P.Join(homedir, ".config", Name)
Path = &path{homedir: homedir}
}
// SetHomeDir is used to set the configuration path
func SetHomeDir(root string) {
Path = &path{homedir: root}
}
func (p *path) HomeDir() string {
return p.homedir
}
func (p *path) Config() string {
return P.Join(p.homedir, "config.yml")
}
func (p *path) MMDB() string {
return P.Join(p.homedir, "Country.mmdb")
}