refactor: extract nested structures in the config.

pull/2100/head
Gordon 2 years ago
parent cd7f35452e
commit 36c8e9e14d

@ -58,37 +58,28 @@ type MYSQL struct {
SlowThreshold int `yaml:"slowThreshold"` SlowThreshold int `yaml:"slowThreshold"`
} }
type GlobalConfig struct { type Zookeeper struct {
Envs struct {
Discovery string `yaml:"discovery"`
}
Zookeeper struct {
Schema string `yaml:"schema"` Schema string `yaml:"schema"`
ZkAddr []string `yaml:"address"` ZkAddr []string `yaml:"address"`
Username string `yaml:"username"` Username string `yaml:"username"`
Password string `yaml:"password"` Password string `yaml:"password"`
} `yaml:"zookeeper"` }
type Mongo struct {
Mysql *MYSQL `yaml:"mysql"`
Mongo struct {
Uri string `yaml:"uri"` Uri string `yaml:"uri"`
Address []string `yaml:"address"` Address []string `yaml:"address"`
Database string `yaml:"database"` Database string `yaml:"database"`
Username string `yaml:"username"` Username string `yaml:"username"`
Password string `yaml:"password"` Password string `yaml:"password"`
MaxPoolSize int `yaml:"maxPoolSize"` MaxPoolSize int `yaml:"maxPoolSize"`
} `yaml:"mongo"` }
type Redis struct {
Redis struct {
ClusterMode bool `yaml:"clusterMode"` ClusterMode bool `yaml:"clusterMode"`
Address []string `yaml:"address"` Address []string `yaml:"address"`
Username string `yaml:"username"` Username string `yaml:"username"`
Password string `yaml:"password"` Password string `yaml:"password"`
EnablePipeline bool `yaml:"enablePipeline"` EnablePipeline bool `yaml:"enablePipeline"`
} `yaml:"redis"` }
type Kafka struct {
Kafka struct {
Username string `yaml:"username"` Username string `yaml:"username"`
Password string `yaml:"password"` Password string `yaml:"password"`
ProducerAck string `yaml:"producerAck"` ProducerAck string `yaml:"producerAck"`
@ -116,22 +107,8 @@ type GlobalConfig struct {
MsgToMySql string `yaml:"msgToMySql"` MsgToMySql string `yaml:"msgToMySql"`
MsgToPush string `yaml:"msgToPush"` MsgToPush string `yaml:"msgToPush"`
} `yaml:"consumerGroupID"` } `yaml:"consumerGroupID"`
} `yaml:"kafka"` }
type Minio struct {
Rpc struct {
RegisterIP string `yaml:"registerIP"`
ListenIP string `yaml:"listenIP"`
} `yaml:"rpc"`
Api struct {
OpenImApiPort []int `yaml:"openImApiPort"`
ListenIP string `yaml:"listenIP"`
} `yaml:"api"`
Object struct {
Enable string `yaml:"enable"`
ApiURL string `yaml:"apiURL"`
Minio struct {
Bucket string `yaml:"bucket"` Bucket string `yaml:"bucket"`
Endpoint string `yaml:"endpoint"` Endpoint string `yaml:"endpoint"`
AccessKeyID string `yaml:"accessKeyID"` AccessKeyID string `yaml:"accessKeyID"`
@ -139,15 +116,15 @@ type GlobalConfig struct {
SessionToken string `yaml:"sessionToken"` SessionToken string `yaml:"sessionToken"`
SignEndpoint string `yaml:"signEndpoint"` SignEndpoint string `yaml:"signEndpoint"`
PublicRead bool `yaml:"publicRead"` PublicRead bool `yaml:"publicRead"`
} `yaml:"minio"` }
Cos struct { type Cos struct {
BucketURL string `yaml:"bucketURL"` BucketURL string `yaml:"bucketURL"`
SecretID string `yaml:"secretID"` SecretID string `yaml:"secretID"`
SecretKey string `yaml:"secretKey"` SecretKey string `yaml:"secretKey"`
SessionToken string `yaml:"sessionToken"` SessionToken string `yaml:"sessionToken"`
PublicRead bool `yaml:"publicRead"` PublicRead bool `yaml:"publicRead"`
} `yaml:"cos"` }
Oss struct { type Oss struct {
Endpoint string `yaml:"endpoint"` Endpoint string `yaml:"endpoint"`
Bucket string `yaml:"bucket"` Bucket string `yaml:"bucket"`
BucketURL string `yaml:"bucketURL"` BucketURL string `yaml:"bucketURL"`
@ -155,8 +132,8 @@ type GlobalConfig struct {
AccessKeySecret string `yaml:"accessKeySecret"` AccessKeySecret string `yaml:"accessKeySecret"`
SessionToken string `yaml:"sessionToken"` SessionToken string `yaml:"sessionToken"`
PublicRead bool `yaml:"publicRead"` PublicRead bool `yaml:"publicRead"`
} `yaml:"oss"` }
Kodo struct { type Kodo struct {
Endpoint string `yaml:"endpoint"` Endpoint string `yaml:"endpoint"`
Bucket string `yaml:"bucket"` Bucket string `yaml:"bucket"`
BucketURL string `yaml:"bucketURL"` BucketURL string `yaml:"bucketURL"`
@ -164,18 +141,29 @@ type GlobalConfig struct {
AccessKeySecret string `yaml:"accessKeySecret"` AccessKeySecret string `yaml:"accessKeySecret"`
SessionToken string `yaml:"sessionToken"` SessionToken string `yaml:"sessionToken"`
PublicRead bool `yaml:"publicRead"` PublicRead bool `yaml:"publicRead"`
} `yaml:"kodo"` }
Aws struct { type Aws struct {
Endpoint string `yaml:"endpoint"` Endpoint string `yaml:"endpoint"`
Region string `yaml:"region"` Region string `yaml:"region"`
Bucket string `yaml:"bucket"` Bucket string `yaml:"bucket"`
AccessKeyID string `yaml:"accessKeyID"` AccessKeyID string `yaml:"accessKeyID"`
AccessKeySecret string `yaml:"accessKeySecret"` AccessKeySecret string `yaml:"accessKeySecret"`
PublicRead bool `yaml:"publicRead"` PublicRead bool `yaml:"publicRead"`
} `yaml:"aws"` }
} `yaml:"object"` type Object struct {
Enable string `yaml:"enable"`
RpcPort struct { ApiURL string `yaml:"apiURL"`
Minio Minio `yaml:"minio"`
Cos Cos `yaml:"cos"`
Oss Oss `yaml:"oss"`
Kodo Kodo `yaml:"kodo"`
Aws Aws `yaml:"aws"`
}
type Api struct {
OpenImApiPort []int `yaml:"openImApiPort"`
ListenIP string `yaml:"listenIP"`
}
type RpcPort struct {
OpenImUserPort []int `yaml:"openImUserPort"` OpenImUserPort []int `yaml:"openImUserPort"`
OpenImFriendPort []int `yaml:"openImFriendPort"` OpenImFriendPort []int `yaml:"openImFriendPort"`
OpenImMessagePort []int `yaml:"openImMessagePort"` OpenImMessagePort []int `yaml:"openImMessagePort"`
@ -186,9 +174,16 @@ type GlobalConfig struct {
OpenImConversationPort []int `yaml:"openImConversationPort"` OpenImConversationPort []int `yaml:"openImConversationPort"`
OpenImRtcPort []int `yaml:"openImRtcPort"` OpenImRtcPort []int `yaml:"openImRtcPort"`
OpenImThirdPort []int `yaml:"openImThirdPort"` OpenImThirdPort []int `yaml:"openImThirdPort"`
} `yaml:"rpcPort"` }
type LongConnSvr struct {
RpcRegisterName struct { OpenImMessageGatewayPort []int `yaml:"openImMessageGatewayPort"`
OpenImWsPort []int `yaml:"openImWsPort"`
WebsocketMaxConnNum int `yaml:"websocketMaxConnNum"`
WebsocketMaxMsgLen int `yaml:"websocketMaxMsgLen"`
WebsocketTimeout int `yaml:"websocketTimeout"`
WebsocketWriteBufferSize int `yaml:"websocketWriteBufferSize"`
}
type RpcRegisterName struct {
OpenImUserName string `yaml:"openImUserName"` OpenImUserName string `yaml:"openImUserName"`
OpenImFriendName string `yaml:"openImFriendName"` OpenImFriendName string `yaml:"openImFriendName"`
OpenImMsgName string `yaml:"openImMsgName"` OpenImMsgName string `yaml:"openImMsgName"`
@ -198,9 +193,8 @@ type GlobalConfig struct {
OpenImAuthName string `yaml:"openImAuthName"` OpenImAuthName string `yaml:"openImAuthName"`
OpenImConversationName string `yaml:"openImConversationName"` OpenImConversationName string `yaml:"openImConversationName"`
OpenImThirdName string `yaml:"openImThirdName"` OpenImThirdName string `yaml:"openImThirdName"`
} `yaml:"rpcRegisterName"` }
type Log struct {
Log struct {
StorageLocation string `yaml:"storageLocation"` StorageLocation string `yaml:"storageLocation"`
RotationTime uint `yaml:"rotationTime"` RotationTime uint `yaml:"rotationTime"`
RemainRotationCount uint `yaml:"remainRotationCount"` RemainRotationCount uint `yaml:"remainRotationCount"`
@ -208,73 +202,55 @@ type GlobalConfig struct {
IsStdout bool `yaml:"isStdout"` IsStdout bool `yaml:"isStdout"`
IsJson bool `yaml:"isJson"` IsJson bool `yaml:"isJson"`
WithStack bool `yaml:"withStack"` WithStack bool `yaml:"withStack"`
} `yaml:"log"` }
type GeTui struct {
LongConnSvr struct {
OpenImMessageGatewayPort []int `yaml:"openImMessageGatewayPort"`
OpenImWsPort []int `yaml:"openImWsPort"`
WebsocketMaxConnNum int `yaml:"websocketMaxConnNum"`
WebsocketMaxMsgLen int `yaml:"websocketMaxMsgLen"`
WebsocketTimeout int `yaml:"websocketTimeout"`
WebsocketWriteBufferSize int `yaml:"websocketWriteBufferSize"`
} `yaml:"longConnSvr"`
Push struct {
MaxConcurrentWorkers int `yaml:"maxConcurrentWorkers"`
Enable string `yaml:"enable"`
GeTui struct {
PushUrl string `yaml:"pushUrl"` PushUrl string `yaml:"pushUrl"`
AppKey string `yaml:"appKey"` AppKey string `yaml:"appKey"`
Intent string `yaml:"intent"` Intent string `yaml:"intent"`
MasterSecret string `yaml:"masterSecret"` MasterSecret string `yaml:"masterSecret"`
ChannelID string `yaml:"channelID"` ChannelID string `yaml:"channelID"`
ChannelName string `yaml:"channelName"` ChannelName string `yaml:"channelName"`
} `yaml:"geTui"` }
Fcm struct { type Fcm struct {
ServiceAccount string `yaml:"serviceAccount"` ServiceAccount string `yaml:"serviceAccount"`
} `yaml:"fcm"` }
Jpns struct { type Jpns struct {
AppKey string `yaml:"appKey"` AppKey string `yaml:"appKey"`
MasterSecret string `yaml:"masterSecret"` MasterSecret string `yaml:"masterSecret"`
PushUrl string `yaml:"pushUrl"` PushUrl string `yaml:"pushUrl"`
PushIntent string `yaml:"pushIntent"` PushIntent string `yaml:"pushIntent"`
} `yaml:"jpns"`
} }
Manager struct { type IOSPush struct {
UserID []string `yaml:"userID"`
Nickname []string `yaml:"nickname"`
} `yaml:"manager"`
IMAdmin struct {
UserID []string `yaml:"userID"`
Nickname []string `yaml:"nickname"`
} `yaml:"im-admin"`
MultiLoginPolicy int `yaml:"multiLoginPolicy"`
ChatPersistenceMysql bool `yaml:"chatPersistenceMysql"`
MsgCacheTimeout int `yaml:"msgCacheTimeout"`
GroupMessageHasReadReceiptEnable bool `yaml:"groupMessageHasReadReceiptEnable"`
SingleMessageHasReadReceiptEnable bool `yaml:"singleMessageHasReadReceiptEnable"`
RetainChatRecords int `yaml:"retainChatRecords"`
ChatRecordsClearTime string `yaml:"chatRecordsClearTime"`
MsgDestructTime string `yaml:"msgDestructTime"`
Secret string `yaml:"secret"`
EnableCronLocker bool `yaml:"enableCronLocker"`
TokenPolicy struct {
Expire int64 `yaml:"expire"`
} `yaml:"tokenPolicy"`
MessageVerify struct {
FriendVerify *bool `yaml:"friendVerify"`
} `yaml:"messageVerify"`
LocalCache localCache `yaml:"localCache"`
IOSPush struct {
PushSound string `yaml:"pushSound"` PushSound string `yaml:"pushSound"`
BadgeCount bool `yaml:"badgeCount"` BadgeCount bool `yaml:"badgeCount"`
Production bool `yaml:"production"` Production bool `yaml:"production"`
} `yaml:"iosPush"` }
Callback struct { type Push struct {
MaxConcurrentWorkers int `yaml:"maxConcurrentWorkers"`
Enable string `yaml:"enable"`
GeTui GeTui `yaml:"geTui"`
Fcm Fcm `yaml:"fcm"`
Jpns Jpns `yaml:"jpns"`
}
type Prometheus struct {
Enable bool `yaml:"enable"`
GrafanaUrl string `yaml:"grafanaUrl"`
ApiPrometheusPort []int `yaml:"apiPrometheusPort"`
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"`
ConversationPrometheusPort []int `yaml:"conversationPrometheusPort"`
RtcPrometheusPort []int `yaml:"rtcPrometheusPort"`
MessageTransferPrometheusPort []int `yaml:"messageTransferPrometheusPort"`
ThirdPrometheusPort []int `yaml:"thirdPrometheusPort"`
}
type Callback struct {
CallbackUrl string `yaml:"url"` CallbackUrl string `yaml:"url"`
CallbackBeforeSendSingleMsg CallBackConfig `yaml:"beforeSendSingleMsg"` CallbackBeforeSendSingleMsg CallBackConfig `yaml:"beforeSendSingleMsg"`
CallbackAfterSendSingleMsg CallBackConfig `yaml:"afterSendSingleMsg"` CallbackAfterSendSingleMsg CallBackConfig `yaml:"afterSendSingleMsg"`
@ -321,24 +297,72 @@ type GlobalConfig struct {
CallbackBeforeImportFriends CallBackConfig `yaml:"importFriendsBefore"` CallbackBeforeImportFriends CallBackConfig `yaml:"importFriendsBefore"`
CallbackAfterImportFriends CallBackConfig `yaml:"importFriendsAfter"` CallbackAfterImportFriends CallBackConfig `yaml:"importFriendsAfter"`
CallbackAfterRemoveBlack CallBackConfig `yaml:"removeBlackAfter"` CallbackAfterRemoveBlack CallBackConfig `yaml:"removeBlackAfter"`
} `yaml:"callback"` }
Prometheus struct { type GlobalConfig struct {
Enable bool `yaml:"enable"` Envs struct {
GrafanaUrl string `yaml:"grafanaUrl"` Discovery string `yaml:"discovery"`
ApiPrometheusPort []int `yaml:"apiPrometheusPort"` }
UserPrometheusPort []int `yaml:"userPrometheusPort"` Zookeeper Zookeeper `yaml:"zookeeper"`
FriendPrometheusPort []int `yaml:"friendPrometheusPort"`
MessagePrometheusPort []int `yaml:"messagePrometheusPort"` Mysql *MYSQL `yaml:"mysql"`
MessageGatewayPrometheusPort []int `yaml:"messageGatewayPrometheusPort"`
GroupPrometheusPort []int `yaml:"groupPrometheusPort"` Mongo Mongo `yaml:"mongo"`
AuthPrometheusPort []int `yaml:"authPrometheusPort"`
PushPrometheusPort []int `yaml:"pushPrometheusPort"` Redis Redis `yaml:"redis"`
ConversationPrometheusPort []int `yaml:"conversationPrometheusPort"`
RtcPrometheusPort []int `yaml:"rtcPrometheusPort"` Kafka Kafka `yaml:"kafka"`
MessageTransferPrometheusPort []int `yaml:"messageTransferPrometheusPort"`
ThirdPrometheusPort []int `yaml:"thirdPrometheusPort"` Rpc struct {
} `yaml:"prometheus"` RegisterIP string `yaml:"registerIP"`
ListenIP string `yaml:"listenIP"`
} `yaml:"rpc"`
Api Api `yaml:"api"`
Object Object `yaml:"object"`
RpcPort RpcPort `yaml:"rpcPort"`
RpcRegisterName RpcRegisterName `yaml:"rpcRegisterName"`
Log Log `yaml:"log"`
LongConnSvr LongConnSvr `yaml:"longConnSvr"`
Push Push `yaml:"push"`
Manager struct {
UserID []string `yaml:"userID"`
Nickname []string `yaml:"nickname"`
} `yaml:"manager"`
IMAdmin struct {
UserID []string `yaml:"userID"`
Nickname []string `yaml:"nickname"`
} `yaml:"im-admin"`
MultiLoginPolicy int `yaml:"multiLoginPolicy"`
MsgCacheTimeout int `yaml:"msgCacheTimeout"`
GroupMessageHasReadReceiptEnable bool `yaml:"groupMessageHasReadReceiptEnable"`
SingleMessageHasReadReceiptEnable bool `yaml:"singleMessageHasReadReceiptEnable"`
RetainChatRecords int `yaml:"retainChatRecords"`
ChatRecordsClearTime string `yaml:"chatRecordsClearTime"`
MsgDestructTime string `yaml:"msgDestructTime"`
Secret string `yaml:"secret"`
EnableCronLocker bool `yaml:"enableCronLocker"`
TokenPolicy struct {
Expire int64 `yaml:"expire"`
} `yaml:"tokenPolicy"`
MessageVerify struct {
FriendVerify *bool `yaml:"friendVerify"`
} `yaml:"messageVerify"`
LocalCache localCache `yaml:"localCache"`
IOSPush IOSPush `yaml:"iosPush"`
Callback Callback `yaml:"callback"`
Prometheus Prometheus `yaml:"prometheus"`
Notification notification `yaml:"notification"` Notification notification `yaml:"notification"`
} }

Loading…
Cancel
Save