|
|
@ -2,7 +2,6 @@ package config
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"OpenIM/pkg/discoveryregistry"
|
|
|
|
"OpenIM/pkg/discoveryregistry"
|
|
|
|
"flag"
|
|
|
|
|
|
|
|
"io/ioutil"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
@ -21,7 +20,7 @@ const (
|
|
|
|
FileName = "config.yaml"
|
|
|
|
FileName = "config.yaml"
|
|
|
|
NotificationFileName = "notification.yaml"
|
|
|
|
NotificationFileName = "notification.yaml"
|
|
|
|
ENV = "CONFIG_NAME"
|
|
|
|
ENV = "CONFIG_NAME"
|
|
|
|
DefaultPath = "../config/"
|
|
|
|
DefaultFolderPath = "../config/"
|
|
|
|
ConfKey = "conf"
|
|
|
|
ConfKey = "conf"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
@ -497,11 +496,12 @@ func (c *config) unmarshalConfig(config interface{}, configPath string) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (c *config) initConfig(config interface{}, configName, configPath string) error {
|
|
|
|
func (c *config) initConfig(config interface{}, configName, configFolderPath string) error {
|
|
|
|
if configPath == "" {
|
|
|
|
if configFolderPath == "" {
|
|
|
|
configPath = DefaultPath
|
|
|
|
configFolderPath = DefaultFolderPath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_, err := os.Stat(filepath.Join(configPath, configName))
|
|
|
|
_, err := os.Stat(filepath.Join(configFolderPath, configName))
|
|
|
|
|
|
|
|
var configPath string
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
configPath = filepath.Join(Root, "config", configName)
|
|
|
|
configPath = filepath.Join(Root, "config", configName)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -521,14 +521,12 @@ func (c *config) GetConfFromRegistry(registry discoveryregistry.SvcDiscoveryRegi
|
|
|
|
return registry.GetConfFromRegistry(ConfKey)
|
|
|
|
return registry.GetConfFromRegistry(ConfKey)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func InitConfig() error {
|
|
|
|
func InitConfig(configFolderPath string) error {
|
|
|
|
configPath := flag.String("config_path", os.Getenv(ENV), "folder for config")
|
|
|
|
err := Config.initConfig(&Config, FileName, configFolderPath)
|
|
|
|
flag.Parse()
|
|
|
|
|
|
|
|
err := Config.initConfig(&Config, FileName, *configPath)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
err = Config.initConfig(&Config.Notification, NotificationFileName, *configPath)
|
|
|
|
err = Config.initConfig(&Config.Notification, NotificationFileName, configFolderPath)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|