You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Open-IM-Server/pkg/common/config/config.go

697 lines
25 KiB

package config
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"gopkg.in/yaml.v3"
)
var (
_, b, _, _ = runtime.Caller(0)
// Root folder of this project
Root = filepath.Join(filepath.Dir(b), "../../..")
)
var Config config
3 years ago
type callBackConfig struct {
Enable bool `yaml:"enable"`
CallbackTimeOut int `yaml:"callbackTimeOut"`
3 years ago
CallbackFailedContinue bool `yaml:"callbackFailedContinue"`
3 years ago
}
type config struct {
3 years ago
ServerIP string `yaml:"serverip"`
RpcRegisterIP string `yaml:"rpcRegisterIP"`
ListenIP string `yaml:"listenIP"`
ServerVersion string `yaml:"serverversion"`
Api struct {
GinPort []int `yaml:"openImApiPort"`
ListenIP string `yaml:"listenIP"`
}
CmsApi struct {
GinPort []int `yaml:"openImCmsApiPort"`
ListenIP string `yaml:"listenIP"`
3 years ago
}
Sdk struct {
WsPort []int `yaml:"openImSdkWsPort"`
DataDir []string `yaml:"dataDir"`
}
Credential struct {
Tencent struct {
AppID string `yaml:"appID"`
Region string `yaml:"region"`
Bucket string `yaml:"bucket"`
SecretID string `yaml:"secretID"`
SecretKey string `yaml:"secretKey"`
}
Ali struct {
RegionID string `yaml:"regionID"`
AccessKeyID string `yaml:"accessKeyID"`
AccessKeySecret string `yaml:"accessKeySecret"`
StsEndpoint string `yaml:"stsEndpoint"`
OssEndpoint string `yaml:"ossEndpoint"`
Bucket string `yaml:"bucket"`
FinalHost string `yaml:"finalHost"`
StsDurationSeconds int64 `yaml:"stsDurationSeconds"`
OssRoleArn string `yaml:"OssRoleArn"`
}
3 years ago
Minio struct {
3 years ago
Bucket string `yaml:"bucket"`
3 years ago
AppBucket string `yaml:"appBucket"`
3 years ago
Location string `yaml:"location"`
Endpoint string `yaml:"endpoint"`
AccessKeyID string `yaml:"accessKeyID"`
SecretAccessKey string `yaml:"secretAccessKey"`
EndpointInner string `yaml:"endpointInner"`
EndpointInnerEnable bool `yaml:"endpointInnerEnable"`
StorageTime int `yaml:"storageTime"`
2 years ago
IsDistributedMod bool `yaml:"isDistributedMod"`
3 years ago
} `yaml:"minio"`
Aws struct {
AccessKeyID string `yaml:"accessKeyID"`
AccessKeySecret string `yaml:"accessKeySecret"`
Region string `yaml:"region"`
Bucket string `yaml:"bucket"`
FinalHost string `yaml:"finalHost"`
RoleArn string `yaml:"roleArn"`
ExternalId string `yaml:"externalId"`
RoleSessionName string `yaml:"roleSessionName"`
} `yaml:"aws"`
}
Mysql struct {
DBAddress []string `yaml:"dbMysqlAddress"`
DBUserName string `yaml:"dbMysqlUserName"`
DBPassword string `yaml:"dbMysqlPassword"`
DBDatabaseName string `yaml:"dbMysqlDatabaseName"`
DBTableName string `yaml:"DBTableName"`
DBMsgTableNum int `yaml:"dbMsgTableNum"`
DBMaxOpenConns int `yaml:"dbMaxOpenConns"`
DBMaxIdleConns int `yaml:"dbMaxIdleConns"`
DBMaxLifeTime int `yaml:"dbMaxLifeTime"`
2 years ago
LogLevel int `yaml:"logLevel"`
SlowThreshold int `yaml:"slowThreshold"`
}
Mongo struct {
DBUri string `yaml:"dbUri"`
DBAddress []string `yaml:"dbAddress"`
DBDirect bool `yaml:"dbDirect"`
DBTimeout int `yaml:"dbTimeout"`
DBDatabase string `yaml:"dbDatabase"`
DBSource string `yaml:"dbSource"`
DBUserName string `yaml:"dbUserName"`
DBPassword string `yaml:"dbPassword"`
DBMaxPoolSize int `yaml:"dbMaxPoolSize"`
DBRetainChatRecords int `yaml:"dbRetainChatRecords"`
ChatRecordsClearTime string `yaml:"chatRecordsClearTime"`
}
Redis struct {
DBAddress []string `yaml:"dbAddress"`
DBMaxIdle int `yaml:"dbMaxIdle"`
DBMaxActive int `yaml:"dbMaxActive"`
DBIdleTimeout int `yaml:"dbIdleTimeout"`
DBUserName string `yaml:"dbUserName"`
DBPassWord string `yaml:"dbPassWord"`
EnableCluster bool `yaml:"enableCluster"`
}
RpcPort struct {
OpenImUserPort []int `yaml:"openImUserPort"`
OpenImFriendPort []int `yaml:"openImFriendPort"`
OpenImMessagePort []int `yaml:"openImMessagePort"`
OpenImMessageGatewayPort []int `yaml:"openImMessageGatewayPort"`
OpenImGroupPort []int `yaml:"openImGroupPort"`
OpenImAuthPort []int `yaml:"openImAuthPort"`
OpenImPushPort []int `yaml:"openImPushPort"`
OpenImAdminCmsPort []int `yaml:"openImAdminCmsPort"`
OpenImOfficePort []int `yaml:"openImOfficePort"`
OpenImOrganizationPort []int `yaml:"openImOrganizationPort"`
OpenImConversationPort []int `yaml:"openImConversationPort"`
OpenImCachePort []int `yaml:"openImCachePort"`
OpenImRealTimeCommPort []int `yaml:"openImRealTimeCommPort"`
}
RpcRegisterName struct {
2 years ago
OpenImUserName string `yaml:"openImUserName"`
OpenImFriendName string `yaml:"openImFriendName"`
2 years ago
// OpenImOfflineMessageName string `yaml:"openImOfflineMessageName"`
OpenImMsgName string `yaml:"openImMsgName"`
OpenImPushName string `yaml:"openImPushName"`
OpenImRelayName string `yaml:"openImRelayName"`
OpenImGroupName string `yaml:"openImGroupName"`
OpenImAuthName string `yaml:"openImAuthName"`
2 years ago
OpenImAdminCMSName string `yaml:"openImAdminCMSName"`
2 years ago
OpenImOfficeName string `yaml:"openImOfficeName"`
OpenImOrganizationName string `yaml:"openImOrganizationName"`
OpenImConversationName string `yaml:"openImConversationName"`
OpenImCacheName string `yaml:"openImCacheName"`
OpenImRealTimeCommName string `yaml:"openImRealTimeCommName"`
}
Etcd struct {
EtcdSchema string `yaml:"etcdSchema"`
EtcdAddr []string `yaml:"etcdAddr"`
2 years ago
UserName string `yaml:"userName"`
Password string `yaml:"password"`
}
Log struct {
StorageLocation string `yaml:"storageLocation"`
RotationTime int `yaml:"rotationTime"`
RemainRotationCount uint `yaml:"remainRotationCount"`
RemainLogLevel uint `yaml:"remainLogLevel"`
ElasticSearchSwitch bool `yaml:"elasticSearchSwitch"`
ElasticSearchAddr []string `yaml:"elasticSearchAddr"`
ElasticSearchUser string `yaml:"elasticSearchUser"`
ElasticSearchPassword string `yaml:"elasticSearchPassword"`
}
ModuleName struct {
LongConnSvrName string `yaml:"longConnSvrName"`
MsgTransferName string `yaml:"msgTransferName"`
PushName string `yaml:"pushName"`
}
LongConnSvr struct {
WebsocketPort []int `yaml:"openImWsPort"`
WebsocketMaxConnNum int `yaml:"websocketMaxConnNum"`
WebsocketMaxMsgLen int `yaml:"websocketMaxMsgLen"`
WebsocketTimeOut int `yaml:"websocketTimeOut"`
}
Push struct {
Tpns struct {
Ios struct {
AccessID string `yaml:"accessID"`
SecretKey string `yaml:"secretKey"`
}
Android struct {
AccessID string `yaml:"accessID"`
SecretKey string `yaml:"secretKey"`
}
3 years ago
Enable bool `yaml:"enable"`
}
Jpns struct {
AppKey string `yaml:"appKey"`
MasterSecret string `yaml:"masterSecret"`
PushUrl string `yaml:"pushUrl"`
3 years ago
PushIntent string `yaml:"pushIntent"`
3 years ago
Enable bool `yaml:"enable"`
}
Getui struct {
3 years ago
PushUrl string `yaml:"pushUrl"`
3 years ago
AppKey string `yaml:"appKey"`
2 years ago
Enable *bool `yaml:"enable"`
3 years ago
Intent string `yaml:"intent"`
MasterSecret string `yaml:"masterSecret"`
2 years ago
ChannelID string `yaml:"channelID"`
ChannelName string `yaml:"channelName"`
}
Fcm struct {
ServiceAccount string `yaml:"serviceAccount"`
Enable bool `yaml:"enable"`
}
Mob struct {
AppKey string `yaml:"appKey"`
PushUrl string `yaml:"pushUrl"`
Scheme string `yaml:"scheme"`
AppSecret string `yaml:"appSecret"`
Enable bool `yaml:"enable"`
}
}
Manager struct {
2 years ago
AppManagerUid []string `yaml:"appManagerUid"`
Secrets []string `yaml:"secrets"`
AppSysNotificationName string `yaml:"appSysNotificationName"`
}
3 years ago
Kafka struct {
2 years ago
SASLUserName string `yaml:"SASLUserName"`
SASLPassword string `yaml:"SASLPassword"`
Ws2mschat struct {
Addr []string `yaml:"addr"`
Topic string `yaml:"topic"`
}
//Ws2mschatOffline struct {
// Addr []string `yaml:"addr"`
// Topic string `yaml:"topic"`
//}
2 years ago
MsgToMongo struct {
Addr []string `yaml:"addr"`
Topic string `yaml:"topic"`
}
Ms2pschat struct {
Addr []string `yaml:"addr"`
Topic string `yaml:"topic"`
}
ConsumerGroupID struct {
MsgToRedis string `yaml:"msgToTransfer"`
MsgToMongo string `yaml:"msgToMongo"`
MsgToMySql string `yaml:"msgToMySql"`
MsgToPush string `yaml:"msgToPush"`
}
}
2 years ago
Secret string `yaml:"secret"`
MultiLoginPolicy int `yaml:"multiloginpolicy"`
ChatPersistenceMysql bool `yaml:"chatpersistencemysql"`
ReliableStorage bool `yaml:"reliablestorage"`
MsgCacheTimeout int `yaml:"msgCacheTimeout"`
GroupMessageHasReadReceiptEnable bool `yaml:"groupMessageHasReadReceiptEnable"`
SingleMessageHasReadReceiptEnable bool `yaml:"singleMessageHasReadReceiptEnable"`
3 years ago
TokenPolicy struct {
AccessSecret string `yaml:"accessSecret"`
AccessExpire int64 `yaml:"accessExpire"`
}
MessageVerify struct {
2 years ago
FriendVerify *bool `yaml:"friendVerify"`
3 years ago
}
3 years ago
IOSPush struct {
PushSound string `yaml:"pushSound"`
BadgeCount bool `yaml:"badgeCount"`
Production bool `yaml:"production"`
3 years ago
}
3 years ago
Callback struct {
CallbackUrl string `yaml:"callbackUrl"`
CallbackBeforeSendSingleMsg callBackConfig `yaml:"callbackBeforeSendSingleMsg"`
CallbackAfterSendSingleMsg callBackConfig `yaml:"callbackAfterSendSingleMsg"`
CallbackBeforeSendGroupMsg callBackConfig `yaml:"callbackBeforeSendGroupMsg"`
CallbackAfterSendGroupMsg callBackConfig `yaml:"callbackAfterSendGroupMsg"`
2 years ago
CallbackMsgModify callBackConfig `yaml:"callbackMsgModify"`
CallbackUserOnline callBackConfig `yaml:"callbackUserOnline"`
CallbackUserOffline callBackConfig `yaml:"callbackUserOffline"`
2 years ago
CallbackUserKickOff callBackConfig `yaml:"callbackUserKickOff"`
CallbackOfflinePush callBackConfig `yaml:"callbackOfflinePush"`
CallbackOnlinePush callBackConfig `yaml:"callbackOnlinePush"`
CallbackBeforeSuperGroupOnlinePush callBackConfig `yaml:"callbackSuperGroupOnlinePush"`
CallbackBeforeAddFriend callBackConfig `yaml:"callbackBeforeAddFriend"`
2 years ago
CallbackBeforeCreateGroup callBackConfig `yaml:"callbackBeforeCreateGroup"`
3 years ago
} `yaml:"callback"`
3 years ago
Notification struct {
3 years ago
///////////////////////group/////////////////////////////
3 years ago
GroupCreated struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"groupCreated"`
3 years ago
3 years ago
GroupInfoSet struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"groupInfoSet"`
3 years ago
3 years ago
JoinGroupApplication struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"joinGroupApplication"`
3 years ago
MemberQuit struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"memberQuit"`
3 years ago
GroupApplicationAccepted struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"groupApplicationAccepted"`
3 years ago
GroupApplicationRejected struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"groupApplicationRejected"`
3 years ago
GroupOwnerTransferred struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"groupOwnerTransferred"`
3 years ago
MemberKicked struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"memberKicked"`
3 years ago
MemberInvited struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"memberInvited"`
3 years ago
MemberEnter struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"memberEnter"`
3 years ago
GroupDismissed struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"groupDismissed"`
3 years ago
GroupMuted struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"groupMuted"`
GroupCancelMuted struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"groupCancelMuted"`
GroupMemberMuted struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"groupMemberMuted"`
GroupMemberCancelMuted struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"groupMemberCancelMuted"`
GroupMemberInfoSet struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"groupMemberInfoSet"`
2 years ago
GroupMemberSetToAdmin struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"groupMemberSetToAdmin"`
GroupMemberSetToOrdinary struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"groupMemberSetToOrdinaryUser"`
3 years ago
OrganizationChanged struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"organizationChanged"`
3 years ago
3 years ago
////////////////////////user///////////////////////
UserInfoUpdated struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"userInfoUpdated"`
3 years ago
3 years ago
//////////////////////friend///////////////////////
3 years ago
FriendApplication struct {
3 years ago
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"friendApplicationAdded"`
3 years ago
FriendApplicationApproved struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"friendApplicationApproved"`
3 years ago
FriendApplicationRejected struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"friendApplicationRejected"`
3 years ago
FriendAdded struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"friendAdded"`
3 years ago
FriendDeleted struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"friendDeleted"`
3 years ago
FriendRemarkSet struct {
3 years ago
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"friendRemarkSet"`
3 years ago
BlackAdded struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"blackAdded"`
3 years ago
BlackDeleted struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
3 years ago
} `yaml:"blackDeleted"`
3 years ago
ConversationOptUpdate struct {
3 years ago
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"conversationOptUpdate"`
ConversationSetPrivate struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
3 years ago
DefaultTips struct {
OpenTips string `yaml:"openTips"`
CloseTips string `yaml:"closeTips"`
} `yaml:"defaultTips"`
} `yaml:"conversationSetPrivate"`
3 years ago
WorkMomentsNotification struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"workMomentsNotification"`
3 years ago
JoinDepartmentNotification struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"joinDepartmentNotification"`
Signal struct {
OfflinePush struct {
Title string `yaml:"title"`
} `yaml:"offlinePush"`
} `yaml:"signal"`
3 years ago
}
Demo struct {
Port []int `yaml:"openImDemoPort"`
ListenIP string `yaml:"listenIP"`
AliSMSVerify struct {
AccessKeyID string `yaml:"accessKeyId"`
AccessKeySecret string `yaml:"accessKeySecret"`
SignName string `yaml:"signName"`
VerificationCodeTemplateCode string `yaml:"verificationCodeTemplateCode"`
2 years ago
Enable bool `yaml:"enable"`
}
TencentSMS struct {
AppID string `yaml:"appID"`
Region string `yaml:"region"`
SecretID string `yaml:"secretID"`
SecretKey string `yaml:"secretKey"`
SignName string `yaml:"signName"`
VerificationCodeTemplateCode string `yaml:"verificationCodeTemplateCode"`
Enable bool `yaml:"enable"`
}
SuperCode string `yaml:"superCode"`
CodeTTL int `yaml:"codeTTL"`
UseSuperCode bool `yaml:"useSuperCode"`
Mail struct {
Title string `yaml:"title"`
SenderMail string `yaml:"senderMail"`
SenderAuthorizationCode string `yaml:"senderAuthorizationCode"`
SmtpAddr string `yaml:"smtpAddr"`
SmtpPort int `yaml:"smtpPort"`
}
2 years ago
TestDepartMentID string `yaml:"testDepartMentID"`
ImAPIURL string `yaml:"imAPIURL"`
NeedInvitationCode bool `yaml:"needInvitationCode"`
OnboardProcess bool `yaml:"onboardProcess"`
JoinDepartmentIDList []string `yaml:"joinDepartmentIDList"`
JoinDepartmentGroups bool `yaml:"joinDepartmentGroups"`
OaNotification bool `yaml:"oaNotification"`
2 years ago
CreateOrganizationUserAndJoinDepartment bool `yaml:"createOrganizationUserAndJoinDepartment"`
}
2 years ago
WorkMoment struct {
OnlyFriendCanSee bool `yaml:"onlyFriendCanSee"`
2 years ago
} `yaml:"workMoment"`
Rtc struct {
SignalTimeout string `yaml:"signalTimeout"`
} `yaml:"rtc"`
2 years ago
Prometheus struct {
Enable bool `yaml:"enable"`
UserPrometheusPort []int `yaml:"userPrometheusPort"`
FriendPrometheusPort []int `yaml:"friendPrometheusPort"`
MessagePrometheusPort []int `yaml:"messagePrometheusPort"`
MessageGatewayPrometheusPort []int `yaml:"messageGatewayPrometheusPort"`
GroupPrometheusPort []int `yaml:"groupPrometheusPort"`
AuthPrometheusPort []int `yaml:"authPrometheusPort"`
PushPrometheusPort []int `yaml:"pushPrometheusPort"`
AdminCmsPrometheusPort []int `yaml:"adminCmsPrometheusPort"`
OfficePrometheusPort []int `yaml:"officePrometheusPort"`
OrganizationPrometheusPort []int `yaml:"organizationPrometheusPort"`
ConversationPrometheusPort []int `yaml:"conversationPrometheusPort"`
CachePrometheusPort []int `yaml:"cachePrometheusPort"`
RealTimeCommPrometheusPort []int `yaml:"realTimeCommPrometheusPort"`
MessageTransferPrometheusPort []int `yaml:"messageTransferPrometheusPort"`
} `yaml:"prometheus"`
}
type PConversation struct {
3 years ago
ReliabilityLevel int `yaml:"reliabilityLevel"`
UnreadCount bool `yaml:"unreadCount"`
}
type POfflinePush struct {
PushSwitch bool `yaml:"switch"`
Title string `yaml:"title"`
Desc string `yaml:"desc"`
Ext string `yaml:"ext"`
}
type PDefaultTips struct {
Tips string `yaml:"tips"`
}
type usualConfig struct {
Etcd struct {
UserName string `yaml:"userName"`
Password string `yaml:"password"`
} `yaml:"etcd"`
Mysql struct {
DBUserName string `yaml:"dbMysqlUserName"`
DBPassword string `yaml:"dbMysqlPassword"`
} `yaml:"mysql"`
Mongo struct {
DBUserName string `yaml:"dbUserName"`
DBPassword string `yaml:"dbPassword"`
} `yaml:"mongo"`
Redis struct {
DBUserName string `yaml:"dbUserName"`
DBPassword string `yaml:"dbPassWord"`
} `yaml:"redis"`
Kafka struct {
SASLUserName string `yaml:"SASLUserName"`
SASLPassword string `yaml:"SASLPassword"`
} `yaml:"kafka"`
Credential struct {
Minio struct {
AccessKeyID string `yaml:"accessKeyID"`
SecretAccessKey string `yaml:"secretAccessKey"`
} `yaml:"minio"`
} `yaml:"credential"`
Messageverify struct {
FriendVerify bool `yaml:"friendVerify"`
}
Push struct {
Getui struct {
MasterSecret string `yaml:"masterSecret"`
AppKey string `yaml:"appKey"`
Enable bool `yaml:"enable"`
}
}
}
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"
}
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())
}
if err = yaml.Unmarshal(bytes, config); err != nil {
panic(err.Error())
}
}
}
func init() {
unmarshalConfig(&Config, "config.yaml")
unmarshalConfig(&UsualConfig, "usualConfig.yaml")
fmt.Println(UsualConfig)
if Config.Etcd.UserName == "" {
Config.Etcd.UserName = UsualConfig.Etcd.UserName
}
if Config.Etcd.Password == "" {
Config.Etcd.Password = UsualConfig.Etcd.Password
}
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
}
2 years ago
if Config.MessageVerify.FriendVerify == nil {
Config.MessageVerify.FriendVerify = &UsualConfig.Messageverify.FriendVerify
}
if Config.Push.Getui.MasterSecret == "" {
Config.Push.Getui.MasterSecret = UsualConfig.Push.Getui.MasterSecret
Config.Push.Getui.AppKey = UsualConfig.Push.Getui.AppKey
}
2 years ago
if Config.Push.Getui.Enable == nil {
Config.Push.Getui.Enable = &UsualConfig.Push.Getui.Enable
}
}