2018-10-14 21:22:58 +08:00
|
|
|
package constant
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2019-03-28 18:20:19 +08:00
|
|
|
"os/user"
|
2018-10-14 21:22:58 +08:00
|
|
|
P "path"
|
|
|
|
)
|
|
|
|
|
|
|
|
const Name = "clash"
|
|
|
|
|
|
|
|
// Path is used to get the configuration path
|
|
|
|
var Path *path
|
|
|
|
|
|
|
|
type path struct {
|
|
|
|
homedir string
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2019-03-28 18:20:19 +08:00
|
|
|
currentUser, err := user.Current()
|
|
|
|
var homedir string
|
2018-10-14 21:22:58 +08:00
|
|
|
if err != nil {
|
2019-03-28 18:20:19 +08:00
|
|
|
dir := os.Getenv("HOME")
|
|
|
|
if dir == "" {
|
|
|
|
dir, _ = os.Getwd()
|
|
|
|
}
|
|
|
|
homedir = dir
|
|
|
|
} else {
|
|
|
|
homedir = currentUser.HomeDir
|
2018-10-14 21:22:58 +08:00
|
|
|
}
|
2019-02-27 01:02:43 +08:00
|
|
|
|
2018-10-14 21:22:58 +08:00
|
|
|
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 {
|
2019-06-18 20:55:26 +08:00
|
|
|
return P.Join(p.homedir, "config.yaml")
|
2018-10-14 21:22:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *path) MMDB() string {
|
|
|
|
return P.Join(p.homedir, "Country.mmdb")
|
|
|
|
}
|