|
|
@ -17,6 +17,7 @@ package config
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
_ "embed"
|
|
|
|
_ "embed"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/OpenIMSDK/tools/errs"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
|
|
|
@ -84,24 +85,22 @@ func GetOptionsByNotification(cfg NotificationConf) msgprocessor.Options {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func initConfig(config any, configName, configFolderPath string) error {
|
|
|
|
func initConfig(config any, configName, configFolderPath string) error {
|
|
|
|
configFolderPath = filepath.Join(configFolderPath, configName)
|
|
|
|
configFullPath := filepath.Join(configFolderPath, configName)
|
|
|
|
_, err := os.Stat(configFolderPath)
|
|
|
|
_, err := os.Stat(configFullPath)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
if !os.IsNotExist(err) {
|
|
|
|
fmt.Println("stat config path error:", err.Error())
|
|
|
|
return errs.Wrap(err, "IsNotExist "+configFolderPath)
|
|
|
|
return fmt.Errorf("stat config path error: %w", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
configFolderPath = filepath.Join(GetProjectRoot(), "config", configName)
|
|
|
|
configFolderPath = filepath.Join(GetProjectRoot(), "config", configName)
|
|
|
|
fmt.Println("flag's path,enviment's path,default path all is not exist,using project path:", configFolderPath)
|
|
|
|
errs.Wrap(fmt.Errorf("flag's path,enviment's path,default path all is not exist,using project path:%s", configFolderPath))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data, err := os.ReadFile(configFolderPath)
|
|
|
|
data, err := os.ReadFile(configFolderPath)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("read file error: %w", err)
|
|
|
|
return errs.Wrap(err, "readFile failed, "+configFolderPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err = yaml.Unmarshal(data, config); err != nil {
|
|
|
|
if err = yaml.Unmarshal(data, config); err != nil {
|
|
|
|
return fmt.Errorf("unmarshal yaml error: %w", err)
|
|
|
|
return errs.Wrap(err, "unmarshal yaml failed, "+configFolderPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fmt.Println("use config", configFolderPath)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|