Skip to content

Commit

Permalink
fix:alter the config.yaml path
Browse files Browse the repository at this point in the history
  • Loading branch information
luhaoling committed Nov 8, 2023
1 parent 9d43247 commit 417593c
Showing 1 changed file with 26 additions and 6 deletions.
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)

Check failure on line 200 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / coverage

undefined: Constant.ConfigPath

Check failure on line 200 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / Test with go 1.19 on ubuntu-latest

undefined: constant.ConfigPath

Check failure on line 200 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / Test with go 1.20 on ubuntu-latest

undefined: Constant.ConfigPath

Check failure on line 200 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / Test with go 1.21 on ubuntu-latest

undefined: Constant.ConfigPath
parentDir := filepath.Dir(p)

path2 := filepath.Join(parentDir, Constant.ConfigPath)

Check failure on line 203 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / coverage

undefined: Constant.ConfigPath

Check failure on line 203 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / Test with go 1.19 on ubuntu-latest

undefined: constant.ConfigPath

Check failure on line 203 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / Test with go 1.20 on ubuntu-latest

undefined: Constant.ConfigPath

Check failure on line 203 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / Test with go 1.21 on ubuntu-latest

undefined: Constant.ConfigPath
parentDir = filepath.Dir(parentDir)
parentDir = filepath.Dir(parentDir)
parentDir = filepath.Dir(parentDir)
parentDir = filepath.Dir(parentDir)
path3 := filepath.Join(parentDir, Constant.ConfigPath)

Check failure on line 208 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / coverage

undefined: Constant.ConfigPath

Check failure on line 208 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / Test with go 1.19 on ubuntu-latest

undefined: constant.ConfigPath

Check failure on line 208 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / Test with go 1.20 on ubuntu-latest

undefined: Constant.ConfigPath

Check failure on line 208 in pkg/common/config/parse.go

View workflow job for this annotation

GitHub Actions / Test with go 1.21 on ubuntu-latest

undefined: 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

0 comments on commit 417593c

Please sign in to comment.