Chore: use iife replace init in some cases

This commit is contained in:
Dreamacro
2021-07-11 19:42:54 +08:00
parent 250a9f4f84
commit 46f4f84442
3 changed files with 13 additions and 21 deletions

View File

@ -9,21 +9,19 @@ import (
const Name = "clash"
// Path is used to get the configuration path
var Path *path
type path struct {
homeDir string
configFile string
}
func init() {
var Path = func() *path {
homeDir, err := os.UserHomeDir()
if err != nil {
homeDir, _ = os.Getwd()
}
homeDir = P.Join(homeDir, ".config", Name)
Path = &path{homeDir: homeDir, configFile: "config.yaml"}
return &path{homeDir: homeDir, configFile: "config.yaml"}
}()
type path struct {
homeDir string
configFile string
}
// SetHomeDir is used to set the configuration path