Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:alter the config.yaml path #259

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions pkg/common/config/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions pkg/common/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading