mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-07 21:17:17 +08:00
fix:config path logic
This commit is contained in:
parent
dfd36a6b7a
commit
419c97cd4a
@ -35,6 +35,16 @@ const (
|
||||
DefaultFolderPath = "../config/"
|
||||
)
|
||||
|
||||
// return absolude path join ../config/, this is k8s container config path
|
||||
func GetDefaultConfigPath() string {
|
||||
b, err := filepath.Abs(os.Args[0])
|
||||
if err != nil {
|
||||
fmt.Println("filepath.Abs error,err=", err)
|
||||
return ""
|
||||
}
|
||||
return filepath.Join(filepath.Dir(b), "../config/")
|
||||
}
|
||||
|
||||
// getProjectRoot returns the absolute path of the project root directory
|
||||
func GetProjectRoot() string {
|
||||
b, _ := filepath.Abs(os.Args[0])
|
||||
@ -65,9 +75,11 @@ func initConfig(config interface{}, configName, configFolderPath string) error {
|
||||
_, err := os.Stat(configFolderPath)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
fmt.Println("stat config path error:", err.Error())
|
||||
return fmt.Errorf("stat config path error: %w", err)
|
||||
}
|
||||
configFolderPath = filepath.Join(GetProjectRoot(), "config", configName)
|
||||
fmt.Println("flag's path,enviment's path,default path all is not exist,using project path:", configFolderPath)
|
||||
}
|
||||
data, err := os.ReadFile(configFolderPath)
|
||||
if err != nil {
|
||||
@ -86,7 +98,7 @@ func InitConfig(configFolderPath string) error {
|
||||
if envConfigPath != "" {
|
||||
configFolderPath = envConfigPath
|
||||
} else {
|
||||
configFolderPath = DefaultFolderPath
|
||||
configFolderPath = GetDefaultConfigPath()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user