From 417593c56566377011b51a5e197c482af0e56c9e Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Wed, 8 Nov 2023 19:18:00 +0800 Subject: [PATCH 1/2] fix:alter the config.yaml path --- pkg/common/config/parse.go | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index 561fe28e..138c0cde 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -196,9 +196,18 @@ func findConfigFile(paths []string) (string, error) { return "", fmt.Errorf("configPath not found") } -func CreateCatalogPath() []string { - - return []string{Constant.ConfigPath1, Constant.ConfigPath2} +func CreateCatalogPath(path string, p string) []string { + path1 := filepath.Join(path, Constant.ConfigPath) + parentDir := filepath.Dir(p) + + path2 := filepath.Join(parentDir, Constant.ConfigPath) + parentDir = filepath.Dir(parentDir) + parentDir = filepath.Dir(parentDir) + parentDir = filepath.Dir(parentDir) + parentDir = filepath.Dir(parentDir) + path3 := filepath.Join(parentDir, Constant.ConfigPath) + + return []string{path1, path2, path3} } func findConfigPath(configFile string) (string, error) { @@ -209,20 +218,31 @@ func findConfigPath(configFile string) (string, error) { if _, err := findConfigFile([]string{configFile}); err != nil { return "", errors.New("the configFile argument path is error") } + fmt.Println("configfile:", configFile) return configFile, nil } // Second, check for OPENIMCONFIG environment variable - envConfigPath := os.Getenv(Constant.OpenIMConfig) + //envConfigPath := os.Getenv(Constant.OpenIMConfig) + envConfigPath := os.Getenv("aaa") if envConfigPath != "" { if _, err := findConfigFile([]string{envConfigPath}); err != nil { return "", errors.New("the environment path config path is error") } return envConfigPath, nil } - // Third, check the catalog to find the config.yaml - path = CreateCatalogPath() + pa, err := os.Getwd() + if err != nil { + return "", err + } + + p1, err := os.Executable() + if err != nil { + return "", err + } + + path = CreateCatalogPath(pa, p1) pathFind, err := findConfigFile(path) if err == nil { return pathFind, nil From eb13f5fb7790e1f028d169bea1cc57bae7774ee0 Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Wed, 8 Nov 2023 19:21:36 +0800 Subject: [PATCH 2/2] fix:fix the const error --- pkg/common/constant/constant.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index ca53f574..9d0086df 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -18,8 +18,7 @@ import "github.com/OpenIMSDK/protocol/constant" // config path const ( - ConfigPath1 = "../config/config.yaml" - ConfigPath2 = "../../../../../config/config.yaml" + ConfigPath = "/config/config.yaml" OpenIMConfig = "OpenIMConfig" // environment variables Default = "../../../config/config.yaml"