Clash.Meta/constant/config.go

52 lines
1.0 KiB
Go
Raw Normal View History

2018-06-10 22:50:03 +08:00
package constant
import (
"os"
"os/user"
"path"
log "github.com/sirupsen/logrus"
)
const (
2018-08-12 02:23:46 +08:00
Name = "clash"
2018-06-10 22:50:03 +08:00
)
var (
HomeDir string
ConfigPath string
MMDBPath string
)
2018-07-15 22:23:20 +08:00
type General struct {
Mode *string `json:"mode,omitempty"`
AllowLan *bool `json:"allow-lan,omitempty"`
Port *int `json:"port,omitempty"`
SocksPort *int `json:"socks-port,omitempty"`
2018-08-26 22:43:38 +08:00
RedirPort *int `json:"redir-port,omitempty"`
LogLevel *string `json:"log-level,omitempty"`
2018-07-15 22:23:20 +08:00
}
2018-06-10 22:50:03 +08:00
func init() {
currentUser, err := user.Current()
if err != nil {
2018-06-17 08:18:39 +08:00
dir := os.Getenv("HOME")
if dir == "" {
log.Fatalf("Can't get current user: %s", err.Error())
}
HomeDir = dir
} else {
HomeDir = currentUser.HomeDir
2018-06-10 22:50:03 +08:00
}
dirPath := path.Join(HomeDir, ".config", Name)
if _, err := os.Stat(dirPath); os.IsNotExist(err) {
if err := os.MkdirAll(dirPath, 0777); err != nil {
log.Fatalf("Can't create config directory %s: %s", dirPath, err.Error())
}
}
ConfigPath = path.Join(dirPath, "config.ini")
MMDBPath = path.Join(dirPath, "Country.mmdb")
}