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/8] 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 561fe28e7..138c0cde6 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/8] 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 ca53f5747..9d0086df8 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" From b711c0a9dc449b85c9cffad64eea6d4446427e82 Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Wed, 8 Nov 2023 20:48:53 +0800 Subject: [PATCH 3/8] fix:update the config.yaml path --- pkg/common/config/parse.go | 41 +++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index 138c0cde6..5cb9545cf 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -196,18 +196,23 @@ func findConfigFile(paths []string) (string, error) { return "", fmt.Errorf("configPath not found") } -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 CreateCatalogPath(path string) []string { + + path1 := filepath.Dir(path) + path1 = filepath.Dir(path1) + // the parent of binary file + path2 := filepath.Join(path1, Constant.ConfigPath) + path2 = filepath.Dir(path1) + path2 = filepath.Dir(path2) + path2 = filepath.Dir(path2) + // the parent is _output + path3 := filepath.Join(path2, Constant.ConfigPath) + path2 = filepath.Dir(path2) + // the parent is project(default) + path4 := filepath.Join(path2, Constant.ConfigPath) + + return []string{path1, path3, path4} + } func findConfigPath(configFile string) (string, error) { @@ -232,24 +237,20 @@ func findConfigPath(configFile string) (string, error) { return envConfigPath, nil } // Third, check the catalog to find the config.yaml - pa, err := os.Getwd() - if err != nil { - return "", err - } p1, err := os.Executable() if err != nil { return "", err } - path = CreateCatalogPath(pa, p1) + path = CreateCatalogPath(p1) pathFind, err := findConfigFile(path) - if err == nil { - return pathFind, nil + if err != nil { + return "", nil } // Forth, use the Default path. - return Constant.Default, nil + return pathFind, nil } func FlagParse() (string, int, bool, bool, error) { From ae06e7aa03003f90e1a7b9a3b6d5d934a8579967 Mon Sep 17 00:00:00 2001 From: luhaoling <2198702716@qq.com> Date: Wed, 8 Nov 2023 20:53:42 +0800 Subject: [PATCH 4/8] fix:update parse.go --- pkg/common/config/parse.go | 2 +- pkg/common/constant/constant.go | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index 5cb9545cf..bb03a285d 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -229,7 +229,7 @@ func findConfigPath(configFile string) (string, error) { // Second, check for OPENIMCONFIG environment variable //envConfigPath := os.Getenv(Constant.OpenIMConfig) - envConfigPath := os.Getenv("aaa") + envConfigPath := os.Getenv(Constant.OpenIMConfig) if envConfigPath != "" { if _, err := findConfigFile([]string{envConfigPath}); err != nil { return "", errors.New("the environment path config path is error") diff --git a/pkg/common/constant/constant.go b/pkg/common/constant/constant.go index 9d0086df8..5468507b2 100644 --- a/pkg/common/constant/constant.go +++ b/pkg/common/constant/constant.go @@ -21,7 +21,6 @@ const ( ConfigPath = "/config/config.yaml" OpenIMConfig = "OpenIMConfig" // environment variables - Default = "../../../config/config.yaml" ) const ( From fc3fe0f575571f53ffee3ec2f3e27cd71d732f20 Mon Sep 17 00:00:00 2001 From: Brabem <69128477+luhaoling@users.noreply.github.com> Date: Wed, 8 Nov 2023 21:03:44 +0800 Subject: [PATCH 5/8] Update parse.go add default path --- pkg/common/config/parse.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index bb03a285d..ad70b9eb2 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -245,12 +245,12 @@ func findConfigPath(configFile string) (string, error) { path = CreateCatalogPath(p1) pathFind, err := findConfigFile(path) - if err != nil { - return "", nil + if err == nil { + return pathFind, nil } // Forth, use the Default path. - return pathFind, nil + return Constant.ConfigPath, nil } func FlagParse() (string, int, bool, bool, error) { From c88843c30b85a5464db6e641f8e7639edd0d5a1f Mon Sep 17 00:00:00 2001 From: Brabem <69128477+luhaoling@users.noreply.github.com> Date: Wed, 8 Nov 2023 21:27:10 +0800 Subject: [PATCH 6/8] Update parse.go --- pkg/common/config/parse.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index ad70b9eb2..1172fb2a8 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -201,17 +201,18 @@ func CreateCatalogPath(path string) []string { path1 := filepath.Dir(path) path1 = filepath.Dir(path1) // the parent of binary file - path2 := filepath.Join(path1, Constant.ConfigPath) - path2 = filepath.Dir(path1) + pa1 := filepath.Join(path1, Constant.ConfigPath) + path2 := filepath.Dir(path1) path2 = filepath.Dir(path2) path2 = filepath.Dir(path2) // the parent is _output - path3 := filepath.Join(path2, Constant.ConfigPath) - path2 = filepath.Dir(path2) - // the parent is project(default) - path4 := filepath.Join(path2, Constant.ConfigPath) + pa2 := filepath.Join(path2, Constant.ConfigPath) + //path3 := filepath.Dir(path2) + //// the parent is project(default) + //pa3 := filepath.Join(path3, Constant.ConfigPath) + + return []string{pa1, pa2} - return []string{path1, path3, path4} } @@ -250,7 +251,7 @@ func findConfigPath(configFile string) (string, error) { } // Forth, use the Default path. - return Constant.ConfigPath, nil + return "", errors.New("the config.yaml path not found") } func FlagParse() (string, int, bool, bool, error) { From c96301e3355cbb024433b3d02297cf9f5b752357 Mon Sep 17 00:00:00 2001 From: Brabem <69128477+luhaoling@users.noreply.github.com> Date: Wed, 8 Nov 2023 21:35:33 +0800 Subject: [PATCH 7/8] Update parse.go --- pkg/common/config/parse.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index 1172fb2a8..97102fa16 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -207,9 +207,9 @@ func CreateCatalogPath(path string) []string { path2 = filepath.Dir(path2) // the parent is _output pa2 := filepath.Join(path2, Constant.ConfigPath) - //path3 := filepath.Dir(path2) - //// the parent is project(default) - //pa3 := filepath.Join(path3, Constant.ConfigPath) + path3 := filepath.Dir(path2) + // the parent is project(default) + pa3 := filepath.Join(path3, Constant.ConfigPath) return []string{pa1, pa2} From b55b6b6b8ebe1b2d254f5fab604465e107d8058f Mon Sep 17 00:00:00 2001 From: Brabem <69128477+luhaoling@users.noreply.github.com> Date: Wed, 8 Nov 2023 21:37:16 +0800 Subject: [PATCH 8/8] Update parse.go --- pkg/common/config/parse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/common/config/parse.go b/pkg/common/config/parse.go index 97102fa16..c5e38b4ab 100644 --- a/pkg/common/config/parse.go +++ b/pkg/common/config/parse.go @@ -211,7 +211,7 @@ func CreateCatalogPath(path string) []string { // the parent is project(default) pa3 := filepath.Join(path3, Constant.ConfigPath) - return []string{pa1, pa2} + return []string{pa1, pa2,pa3} }