From 2d57f742e282d17f6ee1f241f22426cb563cd693 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 20 Apr 2022 18:39:12 +0800 Subject: [PATCH] Organization --- config/config.yaml | 3 +++ internal/api/auth/auth.go | 7 ++++--- .../msg_transfer/logic/persistent_msg_handler.go | 12 ++++++++---- pkg/common/config/config.go | 9 ++++++--- 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index efac38557..598f8bfc2 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -204,6 +204,9 @@ secret: tuoyun # 1:多平台登录:Android、iOS、Windows、Mac 每种平台只能一个在线,web端可以多个同时在线 multiloginpolicy: 1 +#chat log insert to db +chatPersistenceMysql: true + #token config tokenpolicy: accessSecret: "open_im_server" #token生成相关,默认即可 diff --git a/internal/api/auth/auth.go b/internal/api/auth/auth.go index fed744d4f..5e40298c2 100644 --- a/internal/api/auth/auth.go +++ b/internal/api/auth/auth.go @@ -23,8 +23,9 @@ func UserRegister(c *gin.Context) { } if params.Secret != config.Config.Secret { - log.NewError(params.OperationID, "params.Secret != config.Config.Secret", params.Secret, config.Config.Secret) - c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": "not authorized"}) + errMsg := " params.Secret != config.Config.Secret " + log.NewError(params.OperationID, errMsg, params.Secret, config.Config.Secret) + c.JSON(http.StatusBadRequest, gin.H{"errCode": 401, "errMsg": errMsg}) return } req := &rpc.UserRegisterReq{UserInfo: &open_im_sdk.UserInfo{}} @@ -36,7 +37,7 @@ func UserRegister(c *gin.Context) { client := rpc.NewAuthClient(etcdConn) reply, err := client.UserRegister(context.Background(), req) if err != nil { - log.NewError(req.OperationID, "call rpc err ", err) + log.NewError(req.OperationID, "call rpc err ", err.Error()) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "internal service err"}) return } diff --git a/internal/msg_transfer/logic/persistent_msg_handler.go b/internal/msg_transfer/logic/persistent_msg_handler.go index 5400d54d6..0a815ca1a 100644 --- a/internal/msg_transfer/logic/persistent_msg_handler.go +++ b/internal/msg_transfer/logic/persistent_msg_handler.go @@ -56,10 +56,14 @@ func (pc *PersistentConsumerHandler) handleChatWs2Mysql(msg []byte, msgKey strin } } if tag { - log.NewInfo(msgFromMQ.OperationID, "msg_transfer msg persisting", string(msg)) - if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil { - log.NewError(msgFromMQ.OperationID, "Message insert failed", "err", err.Error(), "msg", msgFromMQ.String()) - return + if config.Config.ChatPersistenceMysql == true { + log.NewInfo(msgFromMQ.OperationID, "msg_transfer msg persisting", string(msg)) + if err = im_mysql_msg_model.InsertMessageToChatLog(msgFromMQ); err != nil { + log.NewError(msgFromMQ.OperationID, "Message insert failed", "err", err.Error(), "msg", msgFromMQ.String()) + return + } + } else { + log.Debug(msgFromMQ.OperationID, "don't insert to db", string(msg)) } } diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index 9f51871f3..926ada32e 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -176,6 +176,7 @@ type config struct { AppManagerUid []string `yaml:"appManagerUid"` Secrets []string `yaml:"secrets"` } + Kafka struct { Ws2mschat struct { Addr []string `yaml:"addr"` @@ -191,9 +192,11 @@ type config struct { MsgToPush string `yaml:"msgToPush"` } } - Secret string `yaml:"secret"` - MultiLoginPolicy int `yaml:"multiloginpolicy"` - TokenPolicy struct { + Secret string `yaml:"secret"` + MultiLoginPolicy int `yaml:"multiloginpolicy"` + ChatPersistenceMysql bool `yaml:"chatPersistenceMysql"` + + TokenPolicy struct { AccessSecret string `yaml:"accessSecret"` AccessExpire int64 `yaml:"accessExpire"` }