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

747 lines
26 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), "../../..")
)
const ConfName = "openIMConf"
2 years ago
var Config config
2 years ago
type CallBackConfig struct {
Enable bool `yaml:"enable"`
CallbackTimeOut int `yaml:"callbackTimeOut"`
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"`
2 years ago
Secret string `yaml:"secret"`
}
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"`
}
2 years ago
MsgToModify struct {
Addr []string `yaml:"addr"`
Topic string `yaml:"topic"`
}
ConsumerGroupID struct {
2 years ago
MsgToRedis string `yaml:"msgToTransfer"`
MsgToMongo string `yaml:"msgToMongo"`
MsgToMySql string `yaml:"msgToMySql"`
MsgToPush string `yaml:"msgToPush"`
MsgToModify string `yaml:"msgToModify"`
}
}
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"`
2 years ago
CallbackBeforeSendSingleMsg CallBackConfig `yaml:"callbackBeforeSendSingleMsg"`
CallbackAfterSendSingleMsg CallBackConfig `yaml:"callbackAfterSendSingleMsg"`
CallbackBeforeSendGroupMsg CallBackConfig `yaml:"callbackBeforeSendGroupMsg"`
CallbackAfterSendGroupMsg CallBackConfig `yaml:"callbackAfterSendGroupMsg"`
CallbackMsgModify CallBackConfig `yaml:"callbackMsgModify"`
CallbackUserOnline CallBackConfig `yaml:"callbackUserOnline"`
CallbackUserOffline CallBackConfig `yaml:"callbackUserOffline"`
CallbackUserKickOff CallBackConfig `yaml:"callbackUserKickOff"`
CallbackOfflinePush CallBackConfig `yaml:"callbackOfflinePush"`
CallbackOnlinePush CallBackConfig `yaml:"callbackOnlinePush"`
CallbackBeforeSuperGroupOnlinePush CallBackConfig `yaml:"callbackSuperGroupOnlinePush"`
CallbackBeforeAddFriend CallBackConfig `yaml:"callbackBeforeAddFriend"`
CallbackBeforeCreateGroup CallBackConfig `yaml:"callbackBeforeCreateGroup"`
CallbackBeforeMemberJoinGroup CallBackConfig `yaml:"callbackBeforeMemberJoinGroup"`
CallbackBeforeSetGroupMemberInfo CallBackConfig `yaml:"callbackBeforeSetGroupMemberInfo"`
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"`
FriendInfoUpdated struct {
Conversation PConversation `yaml:"conversation"`
OfflinePush POfflinePush `yaml:"offlinePush"`
DefaultTips PDefaultTips `yaml:"defaultTips"`
} `yaml:"friendInfoUpdated"`
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"`
2 years ago
Secret string `yaml:"secret"`
} `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"`
Endpoint string `yaml:"endpoint"`
} `yaml:"minio"`
} `yaml:"credential"`
2 years ago
Secret string `yaml:"secret"`
Tokenpolicy struct {
AccessSecret string `yaml:"accessSecret"`
AccessExpire int64 `yaml:"accessExpire"`
} `yaml:"tokenpolicy"`
Messageverify struct {
FriendVerify bool `yaml:"friendVerify"`
2 years ago
} `yaml:"messageverify"`
Push struct {
Getui struct {
PushUrl string `yaml:"pushUrl"`
MasterSecret string `yaml:"masterSecret"`
AppKey string `yaml:"appKey"`
Enable bool `yaml:"enable"`
2 years ago
} `yaml:"getui"`
} `yaml:"push"`
}
var UsualConfig usualConfig
2 years ago
func unmarshalConfig(config interface{}, configPath string) {
bytes, err := ioutil.ReadFile(configPath)
if err != nil {
panic(err.Error() + configPath)
}
if err = yaml.Unmarshal(bytes, config); err != nil {
panic(err.Error())
}
}
func initConfig(config interface{}, configName, configPath string) {
if configPath == "" {
2 years ago
var env string
2 years ago
if configName == "config.yaml" {
env = "CONFIG_NAME"
} else if configName == "usualConfig.yaml" {
env = "USUAL_CONFIG_NAME"
}
cfgName := os.Getenv(env)
if len(cfgName) != 0 {
2 years ago
configPath = filepath.Join(cfgName, "config", configName)
_, err := os.Stat(configPath)
if os.IsNotExist(err) {
configPath = filepath.Join(Root, "config", configName)
2 years ago
} else {
Root = cfgName
}
} else {
2 years ago
configPath = fmt.Sprintf("../config/%s", configName)
}
2 years ago
}
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() {
2 years ago
InitConfig("")
2 years ago
}