clash/constant/path.go

43 lines
664 B
Go
Raw Normal View History

2018-10-14 13:22:58 +00:00
package constant
import (
"os"
P "path"
)
const Name = "clash"
// Path is used to get the configuration path
var Path *path
type path struct {
homedir string
}
func init() {
2019-09-04 14:26:20 +00:00
homedir, err := os.UserHomeDir()
2018-10-14 13:22:58 +00:00
if err != nil {
2019-09-04 14:26:20 +00:00
homedir, _ = os.Getwd()
2018-10-14 13:22:58 +00:00
}
2019-02-26 17:02:43 +00:00
2018-10-14 13:22:58 +00: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 {
return P.Join(p.homedir, "config.yaml")
2018-10-14 13:22:58 +00:00
}
func (p *path) MMDB() string {
return P.Join(p.homedir, "Country.mmdb")
}