github.com/Asutorufa/yuhaiin@v0.3.6-0.20240502055049-7984da7023a0/pkg/protos/config/config.go (about) 1 package config 2 3 import ( 4 "os" 5 "os/exec" 6 "path/filepath" 7 8 "github.com/Asutorufa/yuhaiin/pkg/log" 9 ) 10 11 func DefaultConfigDir() (Path string) { 12 var err error 13 Path, err = os.UserConfigDir() 14 if err == nil { 15 Path = filepath.Join(Path, "yuhaiin") 16 return 17 } 18 19 file, err := exec.LookPath(os.Args[0]) 20 if err != nil { 21 log.Warn("lookpath failed", "err", err) 22 Path = filepath.Join(".", "yuhaiin") 23 return 24 } 25 execPath, err := filepath.Abs(file) 26 if err != nil { 27 log.Warn("get file abs failed", "err", err) 28 Path = filepath.Join(".", "yuhaiin") 29 return 30 } 31 32 Path = filepath.Join(filepath.Dir(execPath), "config") 33 return 34 }