2018-10-14 21:22:58 +08:00
|
|
|
package constant
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
P "path"
|
|
|
|
)
|
|
|
|
|
|
|
|
const Name = "clash"
|
|
|
|
|
|
|
|
// Path is used to get the configuration path
|
|
|
|
var Path *path
|
|
|
|
|
|
|
|
type path struct {
|
2019-10-14 18:11:22 +08:00
|
|
|
homeDir string
|
|
|
|
configFile string
|
2018-10-14 21:22:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2019-10-14 18:11:22 +08:00
|
|
|
homeDir, err := os.UserHomeDir()
|
2018-10-14 21:22:58 +08:00
|
|
|
if err != nil {
|
2019-10-14 18:11:22 +08:00
|
|
|
homeDir, _ = os.Getwd()
|
2018-10-14 21:22:58 +08:00
|
|
|
}
|
2019-02-27 01:02:43 +08:00
|
|
|
|
2019-10-14 18:11:22 +08:00
|
|
|
homeDir = P.Join(homeDir, ".config", Name)
|
|
|
|
Path = &path{homeDir: homeDir, configFile: "config.yaml"}
|
2018-10-14 21:22:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// SetHomeDir is used to set the configuration path
|
|
|
|
func SetHomeDir(root string) {
|
2019-10-14 18:11:22 +08:00
|
|
|
Path.homeDir = root
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetConfig is used to set the configuration file
|
|
|
|
func SetConfig(file string) {
|
|
|
|
Path.configFile = file
|
2018-10-14 21:22:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *path) HomeDir() string {
|
2019-10-14 18:11:22 +08:00
|
|
|
return p.homeDir
|
2018-10-14 21:22:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *path) Config() string {
|
2019-10-14 18:11:22 +08:00
|
|
|
return p.configFile
|
2018-10-14 21:22:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *path) MMDB() string {
|
2019-10-14 18:11:22 +08:00
|
|
|
return P.Join(p.homeDir, "Country.mmdb")
|
2018-10-14 21:22:58 +08:00
|
|
|
}
|