mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2024-09-05 08:32:33 +00:00
58 lines
1,011 B
Go
58 lines
1,011 B
Go
package constant
|
|
|
|
import (
|
|
"os"
|
|
P "path"
|
|
"path/filepath"
|
|
)
|
|
|
|
const Name = "clash"
|
|
|
|
// Path is used to get the configuration path
|
|
var Path *path
|
|
|
|
type path struct {
|
|
homeDir string
|
|
configFile string
|
|
}
|
|
|
|
func init() {
|
|
homeDir, err := os.UserHomeDir()
|
|
if err != nil {
|
|
homeDir, _ = os.Getwd()
|
|
}
|
|
|
|
homeDir = P.Join(homeDir, ".config", Name)
|
|
Path = &path{homeDir: homeDir, configFile: "config.yaml"}
|
|
}
|
|
|
|
// SetHomeDir is used to set the configuration path
|
|
func SetHomeDir(root string) {
|
|
Path.homeDir = root
|
|
}
|
|
|
|
// SetConfig is used to set the configuration file
|
|
func SetConfig(file string) {
|
|
Path.configFile = file
|
|
}
|
|
|
|
func (p *path) HomeDir() string {
|
|
return p.homeDir
|
|
}
|
|
|
|
func (p *path) Config() string {
|
|
return p.configFile
|
|
}
|
|
|
|
// Resolve return a absolute path or a relative path with homedir
|
|
func (p *path) Resolve(path string) string {
|
|
if !filepath.IsAbs(path) {
|
|
return filepath.Join(p.HomeDir(), path)
|
|
}
|
|
|
|
return path
|
|
}
|
|
|
|
func (p *path) MMDB() string {
|
|
return P.Join(p.homeDir, "Country.mmdb")
|
|
}
|