mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-03 00:25:59 +08:00
del files
This commit is contained in:
+128
-31
@@ -629,41 +629,138 @@ type usualConfig struct {
|
||||
|
||||
var UsualConfig usualConfig
|
||||
|
||||
func unmarshalConfig(config interface{}, configName string) {
|
||||
var env string
|
||||
if configName == "config.yaml" {
|
||||
env = "CONFIG_NAME"
|
||||
} else if configName == "usualConfig.yaml" {
|
||||
env = "USUAL_CONFIG_NAME"
|
||||
func unmarshalConfig(config interface{}, configPath string) {
|
||||
bytes, err := ioutil.ReadFile(configPath)
|
||||
if err != nil {
|
||||
panic(err.Error() + configPath)
|
||||
}
|
||||
cfgName := os.Getenv(env)
|
||||
if len(cfgName) != 0 {
|
||||
bytes, err := ioutil.ReadFile(filepath.Join(cfgName, "config", configName))
|
||||
if err != nil {
|
||||
bytes, err = ioutil.ReadFile(filepath.Join(Root, "config", configName))
|
||||
if err != nil {
|
||||
panic(err.Error() + " config: " + filepath.Join(cfgName, "config", configName))
|
||||
}
|
||||
} else {
|
||||
Root = cfgName
|
||||
}
|
||||
if err = yaml.Unmarshal(bytes, config); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
} else {
|
||||
bytes, err := ioutil.ReadFile(fmt.Sprintf("../config/%s", configName))
|
||||
if err != nil {
|
||||
panic(err.Error() + configName)
|
||||
}
|
||||
if err = yaml.Unmarshal(bytes, config); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
if err = yaml.Unmarshal(bytes, config); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
unmarshalConfig(&Config, "config.yaml")
|
||||
unmarshalConfig(&UsualConfig, "usualConfig.yaml")
|
||||
func initConfig(config interface{}, configName, configPath string) {
|
||||
var env string
|
||||
if configPath == "" {
|
||||
if configName == "config.yaml" {
|
||||
env = "CONFIG_NAME"
|
||||
} else if configName == "usualConfig.yaml" {
|
||||
env = "USUAL_CONFIG_NAME"
|
||||
}
|
||||
cfgName := os.Getenv(env)
|
||||
if len(cfgName) != 0 {
|
||||
bytes, err := ioutil.ReadFile(filepath.Join(cfgName, "config", configName))
|
||||
if err != nil {
|
||||
bytes, err = ioutil.ReadFile(filepath.Join(Root, "config", configName))
|
||||
if err != nil {
|
||||
panic(err.Error() + " config: " + filepath.Join(cfgName, "config", configName))
|
||||
}
|
||||
} else {
|
||||
Root = cfgName
|
||||
}
|
||||
if err = yaml.Unmarshal(bytes, config); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return
|
||||
} else {
|
||||
bytes, err := ioutil.ReadFile(fmt.Sprintf("../config/%s", configName))
|
||||
if err != nil {
|
||||
panic(err.Error() + configName)
|
||||
}
|
||||
if err = yaml.Unmarshal(bytes, config); err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
}
|
||||
|
||||
unmarshalConfig(config, configPath)
|
||||
}
|
||||
|
||||
func InitConfig(configPath string) {
|
||||
initConfig(&Config, "config.yaml", configPath)
|
||||
initConfig(&UsualConfig, "usualConfig.yaml", configPath)
|
||||
if Config.Etcd.UserName == "" {
|
||||
Config.Etcd.UserName = UsualConfig.Etcd.UserName
|
||||
}
|
||||
if Config.Etcd.Password == "" {
|
||||
Config.Etcd.Password = UsualConfig.Etcd.Password
|
||||
}
|
||||
if Config.Etcd.Secret == "" {
|
||||
Config.Etcd.Secret = UsualConfig.Etcd.Secret
|
||||
}
|
||||
|
||||
if Config.Mysql.DBUserName == "" {
|
||||
Config.Mysql.DBUserName = UsualConfig.Mysql.DBUserName
|
||||
}
|
||||
if Config.Mysql.DBPassword == "" {
|
||||
Config.Mysql.DBPassword = UsualConfig.Mysql.DBPassword
|
||||
}
|
||||
|
||||
if Config.Redis.DBUserName == "" {
|
||||
Config.Redis.DBUserName = UsualConfig.Redis.DBUserName
|
||||
}
|
||||
if Config.Redis.DBPassWord == "" {
|
||||
Config.Redis.DBPassWord = UsualConfig.Redis.DBPassword
|
||||
}
|
||||
|
||||
if Config.Mongo.DBUserName == "" {
|
||||
Config.Mongo.DBUserName = UsualConfig.Mongo.DBUserName
|
||||
}
|
||||
if Config.Mongo.DBPassword == "" {
|
||||
Config.Mongo.DBPassword = UsualConfig.Mongo.DBPassword
|
||||
}
|
||||
|
||||
if Config.Kafka.SASLUserName == "" {
|
||||
Config.Kafka.SASLUserName = UsualConfig.Kafka.SASLUserName
|
||||
}
|
||||
if Config.Kafka.SASLPassword == "" {
|
||||
Config.Kafka.SASLPassword = UsualConfig.Kafka.SASLPassword
|
||||
}
|
||||
|
||||
if Config.Credential.Minio.AccessKeyID == "" {
|
||||
Config.Credential.Minio.AccessKeyID = UsualConfig.Credential.Minio.AccessKeyID
|
||||
}
|
||||
if Config.Credential.Minio.SecretAccessKey == "" {
|
||||
Config.Credential.Minio.SecretAccessKey = UsualConfig.Credential.Minio.SecretAccessKey
|
||||
}
|
||||
if Config.Credential.Minio.Endpoint == "" {
|
||||
Config.Credential.Minio.Endpoint = UsualConfig.Credential.Minio.Endpoint
|
||||
}
|
||||
|
||||
if Config.MessageVerify.FriendVerify == nil {
|
||||
Config.MessageVerify.FriendVerify = &UsualConfig.Messageverify.FriendVerify
|
||||
}
|
||||
|
||||
if Config.Push.Getui.MasterSecret == "" {
|
||||
Config.Push.Getui.MasterSecret = UsualConfig.Push.Getui.MasterSecret
|
||||
}
|
||||
if Config.Push.Getui.AppKey == "" {
|
||||
Config.Push.Getui.AppKey = UsualConfig.Push.Getui.AppKey
|
||||
}
|
||||
if Config.Push.Getui.PushUrl == "" {
|
||||
Config.Push.Getui.PushUrl = UsualConfig.Push.Getui.PushUrl
|
||||
}
|
||||
if Config.Push.Getui.Enable == nil {
|
||||
Config.Push.Getui.Enable = &UsualConfig.Push.Getui.Enable
|
||||
}
|
||||
|
||||
if Config.Secret == "" {
|
||||
Config.Secret = UsualConfig.Secret
|
||||
}
|
||||
|
||||
if Config.TokenPolicy.AccessExpire == 0 {
|
||||
Config.TokenPolicy.AccessExpire = UsualConfig.Tokenpolicy.AccessExpire
|
||||
}
|
||||
if Config.TokenPolicy.AccessSecret == "" {
|
||||
Config.TokenPolicy.AccessSecret = UsualConfig.Tokenpolicy.AccessSecret
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
initConfig(&Config, "config.yaml", "")
|
||||
initConfig(&UsualConfig, "usualConfig.yaml", "")
|
||||
if Config.Etcd.UserName == "" {
|
||||
Config.Etcd.UserName = UsualConfig.Etcd.UserName
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user