修复$HOME未定义问题

This commit is contained in:
刘祥超
2021-02-01 09:26:20 +08:00
parent 009b48602e
commit 2bc3d1f81b

View File

@@ -34,14 +34,15 @@ func SharedAPIConfig() (*APIConfig, error) {
localFile := Tea.ConfigFile("api.yaml")
isFromLocal := false
paths := []string{localFile}
homeDir, err := os.UserHomeDir()
if err == nil {
homeDir, homeErr := os.UserHomeDir()
if homeErr == nil {
paths = append(paths, homeDir+"/."+teaconst.ProcessName+"/api.yaml")
}
paths = append(paths, "/etc/"+teaconst.ProcessName+"/api.yaml")
// 依次检查文件
var data []byte
var err error
for _, path := range paths {
data, err = ioutil.ReadFile(path)
if err == nil {
@@ -73,8 +74,8 @@ func SharedAPIConfig() (*APIConfig, error) {
_, err := os.Stat(dbConfigFile)
if err == nil {
paths := []string{}
homeDir, err := os.UserHomeDir()
if err == nil {
homeDir, homeErr := os.UserHomeDir()
if homeErr == nil {
paths = append(paths, homeDir+"/."+teaconst.ProcessName+"/db.yaml")
}
paths = append(paths, "/etc/"+teaconst.ProcessName+"/db.yaml")