From 7e44f7f110cc8bc5e8fe84accf8ba7ebfe0dcf83 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 10:33:49 +0800 Subject: [PATCH 01/12] cache rpc --- cmd/rpc/open_im_cache/Makefile | 24 +++++ cmd/rpc/open_im_cache/main.go | 16 ++++ config/config.yaml | 1 + internal/api/user/user.go | 156 +++++++-------------------------- pkg/proto/cache/cache.proto | 28 ++++-- script/check_all.sh | 1 + script/path_info.cfg | 2 + script/start_rpc_service.sh | 2 + 8 files changed, 100 insertions(+), 130 deletions(-) create mode 100644 cmd/rpc/open_im_cache/Makefile create mode 100644 cmd/rpc/open_im_cache/main.go diff --git a/cmd/rpc/open_im_cache/Makefile b/cmd/rpc/open_im_cache/Makefile new file mode 100644 index 000000000..1cb1e959e --- /dev/null +++ b/cmd/rpc/open_im_cache/Makefile @@ -0,0 +1,24 @@ +.PHONY: all build run gotool install clean help + +BINARY_NAME=open_im_cache +BIN_DIR=../../../bin/ + +all: gotool build + +build: + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" + +run: + @go run ./ + +gotool: + go fmt ./ + go vet ./ + +install: + make build + mv ${BINARY_NAME} ${BIN_DIR} + +clean: + @if [ -f ${BINARY_NAME} ] ; then rm ${BINARY_NAME} ; fi + diff --git a/cmd/rpc/open_im_cache/main.go b/cmd/rpc/open_im_cache/main.go new file mode 100644 index 000000000..2ab2eefa8 --- /dev/null +++ b/cmd/rpc/open_im_cache/main.go @@ -0,0 +1,16 @@ +package main + +import ( + rpcCache "Open_IM/internal/rpc/cache" + "flag" + "fmt" +) + +func main() { + rpcPort := flag.Int("port", 10600, "RpcToken default listen port 10800") + flag.Parse() + fmt.Println("start auth rpc server, port: ", *rpcPort) + rpcServer := rpcCache.NewOfficeServer(*rpcPort) + rpcServer.Run() + +} diff --git a/config/config.yaml b/config/config.yaml index 4bb653511..770fc31f6 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -124,6 +124,7 @@ rpcport: #rpc服务端口 默认即可 openImOfficePort: [ 10210 ] openImOrganizationPort: [ 10220 ] openImConversationPort: [ 10230 ] + openImCachePort: [10240] c2c: callbackBeforeSendMsg: switch: false diff --git a/internal/api/user/user.go b/internal/api/user/user.go index b7cb4c3df..af8448522 100644 --- a/internal/api/user/user.go +++ b/internal/api/user/user.go @@ -8,7 +8,6 @@ import ( "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" "Open_IM/pkg/grpc-etcdv3/getcdv3" - "Open_IM/pkg/proto/cache" pbRelay "Open_IM/pkg/proto/relay" open_im_sdk "Open_IM/pkg/proto/sdk_ws" rpc "Open_IM/pkg/proto/user" @@ -58,6 +57,14 @@ func GetUsersInfoFromCache(c *gin.Context) { c.JSON(http.StatusOK, resp) } +func GetUserFriendFromCache(c *gin.Context) { + +} + +func GetBlackListFromCache(c *gin.Context) { + +} + func GetUsersInfo(c *gin.Context) { params := api.GetUsersInfoReq{} if err := c.BindJSON(¶ms); err != nil { @@ -65,100 +72,34 @@ func GetUsersInfo(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()}) return } - getUserInfoReq := &rpc.GetUserInfoReq{} - getUserInfoReq.OperationID = params.OperationID + req := &rpc.GetUserInfoReq{} + utils.CopyStructFields(req, ¶ms) var ok bool - ok, getUserInfoReq.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), getUserInfoReq.OperationID) + ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) if !ok { - log.NewError(getUserInfoReq.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) + log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) return } - log.NewInfo(params.OperationID, "GetUserInfo args ", getUserInfoReq.String()) - reqCacheGetUserInfo := &cache.GetUserInfoReq{} - utils.CopyStructFields(reqCacheGetUserInfo, ¶ms) - var userInfoList []*open_im_sdk.UserInfo - var publicUserInfoList []*open_im_sdk.PublicUserInfo - etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName) - cacheClient := cache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.GetUserInfo(context.Background(), reqCacheGetUserInfo) - if err != nil { - log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", err.Error()) - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed: " + err.Error()}) - return - } - if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp) - resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} - resp.Data = []map[string]interface{}{} - log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) - c.JSON(http.StatusOK, resp) - return - } - log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "cacheResp:", cacheResp.String()) - userInfoList = cacheResp.UserInfoList - var needCacheUserIDList []string - for _, userID := range reqCacheGetUserInfo.UserIDList { - isGetUserInfoFromCache := false - for _, cacheUser := range userInfoList { - if cacheUser.UserID == userID { - isGetUserInfoFromCache = true - } - } - if !isGetUserInfoFromCache { - needCacheUserIDList = append(needCacheUserIDList, userID) - } - } - if len(needCacheUserIDList) == 0 { - log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "get all userInfo from cache success") - for _, v := range userInfoList { - publicUserInfoList = append(publicUserInfoList, - &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) - } - resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} - resp.Data = jsonData.JsonDataList(resp.UserInfoList) - log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) - c.JSON(http.StatusOK, resp) - return - } + log.NewInfo(params.OperationID, "GetUserInfo args ", req.String()) - log.NewDebug(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "need cache user list", needCacheUserIDList) - getUserInfoReq.UserIDList = needCacheUserIDList - etcdConn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := rpc.NewUserClient(etcdConn) - rpcResp, err := client.GetUserInfo(context.Background(), getUserInfoReq) + RpcResp, err := client.GetUserInfo(context.Background(), req) if err != nil { - log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error(), getUserInfoReq.String()) - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed" + err.Error()}) - return - } - if rpcResp.CommonResp.ErrCode != 0 { - log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp) - resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} - resp.Data = []map[string]interface{}{} - log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) - c.JSON(http.StatusOK, resp) - return - } - userInfoList = append(userInfoList, rpcResp.UserInfoList...) - cacheUpdateUserInfoReq := &cache.UpdateUserInfoReq{ - UserInfoList: rpcResp.UserInfoList, - OperationID: getUserInfoReq.OperationID, - } - _, err = cacheClient.UpdateUserInfo(context.Background(), cacheUpdateUserInfoReq) - if err != nil { - log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error()) + log.NewError(req.OperationID, "GetUserInfo failed ", err.Error(), req.String()) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"}) return } - userInfoList = rpcResp.UserInfoList - for _, v := range userInfoList { + var publicUserInfoList []*open_im_sdk.PublicUserInfo + for _, v := range RpcResp.UserInfoList { publicUserInfoList = append(publicUserInfoList, &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) } - resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} + + resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} resp.Data = jsonData.JsonDataList(resp.UserInfoList) - log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) + log.NewInfo(req.OperationID, "GetUserInfo api return ", resp) c.JSON(http.StatusOK, resp) } @@ -181,34 +122,18 @@ func UpdateUserInfo(c *gin.Context) { return } log.NewInfo(params.OperationID, "UpdateUserInfo args ", req.String()) - etcdConnUser := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) - client := rpc.NewUserClient(etcdConnUser) - rpcResp, err := client.UpdateUserInfo(context.Background(), req) + + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) + client := rpc.NewUserClient(etcdConn) + RpcResp, err := client.UpdateUserInfo(context.Background(), req) if err != nil { log.NewError(req.OperationID, "UpdateUserInfo failed ", err.Error(), req.String()) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"}) return } - if rpcResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, utils.GetSelfFuncName(), rpcResp.CommonResp.String()) - resp := api.UpdateUserInfoResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}} - c.JSON(http.StatusOK, resp) - return - } else { - updateUserInfoReq := &cache.UpdateUserInfoReq{UserInfoList: []*open_im_sdk.UserInfo{req.UserInfo}} - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), updateUserInfoReq.String()) - etcdConnCache := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName) - cacheClient := cache.NewCacheClient(etcdConnCache) - cacheResp, err := cacheClient.UpdateUserInfo(context.Background(), updateUserInfoReq) - if err != nil { - log.NewError(req.OperationID, "UpdateUserInfo cache failed ", err.Error(), req.String()) - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed: " + err.Error()}) - return - } - resp := api.UpdateUserInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} - log.NewInfo(req.OperationID, "UpdateUserInfo api return ", resp) - c.JSON(http.StatusOK, resp) - } + resp := api.UpdateUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}} + log.NewInfo(req.OperationID, "UpdateUserInfo api return ", resp) + c.JSON(http.StatusOK, resp) } func GetSelfUserInfo(c *gin.Context) { @@ -240,31 +165,16 @@ func GetSelfUserInfo(c *gin.Context) { return } if len(RpcResp.UserInfoList) == 1 { - updateUserInfoReq := &cache.UpdateUserInfoReq{UserInfoList: []*open_im_sdk.UserInfo{RpcResp.UserInfoList[0]}} - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), updateUserInfoReq.String()) - etcdConnCache := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName) - cacheClient := cache.NewCacheClient(etcdConnCache) - cacheClient.UpdateUserInfo(context.Background(), updateUserInfoReq) - //if err != nil { - // log.NewError(req.OperationID, "UpdateUserInfo cache failed ", err.Error(), req.String()) - // c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed: " + err.Error()}) - // return - //} - //if cacheResp.CommonResp.ErrCode != 0 { - // log.NewError(req.OperationID, utils.GetSelfFuncName(), cacheResp.CommonResp.String()) - // resp := api.UpdateUserInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} - // c.JSON(http.StatusOK, resp) - // return - //} - //resp := api.GetSelfUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfo: RpcResp.UserInfoList[0]} - //resp.Data = jsonData.JsonDataOne(resp.UserInfo) - //log.NewInfo(req.OperationID, "GetUserInfo api return ", resp) - //c.JSON(http.StatusOK, resp) + resp := api.GetSelfUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfo: RpcResp.UserInfoList[0]} + resp.Data = jsonData.JsonDataOne(resp.UserInfo) + log.NewInfo(req.OperationID, "GetUserInfo api return ", resp) + c.JSON(http.StatusOK, resp) } else { resp := api.GetSelfUserInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}} log.NewInfo(req.OperationID, "GetUserInfo api return ", resp) c.JSON(http.StatusOK, resp) } + } func GetUsersOnlineStatus(c *gin.Context) { diff --git a/pkg/proto/cache/cache.proto b/pkg/proto/cache/cache.proto index cecfabd3c..c618c20f8 100644 --- a/pkg/proto/cache/cache.proto +++ b/pkg/proto/cache/cache.proto @@ -15,12 +15,12 @@ message GetUserInfoReq{ message GetUserInfoResp{ CommonResp commonResp = 1; - repeated server_api_params.UserInfo UserInfoList = 2; + repeated server_api_params.UserInfo userInfoList = 2; } message UpdateUserInfoReq{ - repeated server_api_params.UserInfo UserInfoList = 1; + repeated server_api_params.UserInfo userInfoList = 1; string operationID = 2; } @@ -28,17 +28,31 @@ message UpdateUserInfoResp{ CommonResp commonResp = 1; } -message UpdateAllUserToCacheReq{ - string operationID = 1; + +message GetFriendInfoReq { + } -message UpdateAllUserToCacheResp{ +message GetFriendInfoResp { + +} + + +message UpdateFriendInfoReq{ + repeated server_api_params.FriendInfo friendInfoList = 1; + string operationID = 2; +} + +message UpdateFriendInfoResp{ CommonResp commonResp = 1; } - service cache{ rpc GetUserInfo(GetUserInfoReq) returns(GetUserInfoResp); rpc UpdateUserInfo(UpdateUserInfoReq) returns(UpdateUserInfoResp); - rpc UpdateAllUserToCache(UpdateAllUserToCacheReq) returns(UpdateAllUserToCacheResp); + rpc GetFriendInfo(GetFriendInfoReq) returns(GetFriendInfoResp); + rpc UpdateFriendInfo(UpdateFriendInfoReq) returns(UpdateFriendInfoResp); + rpc } + + diff --git a/script/check_all.sh b/script/check_all.sh index 60abfad69..ccd62684b 100644 --- a/script/check_all.sh +++ b/script/check_all.sh @@ -22,6 +22,7 @@ service_port_name=( openImOfficePort openImOrganizationPort openImConversationPort + openImCachePort ) switch=$(cat $config_path | grep demoswitch |awk -F '[:]' '{print $NF}') for i in ${service_port_name[*]}; do diff --git a/script/path_info.cfg b/script/path_info.cfg index 3071a0a5d..9c9b0c264 100644 --- a/script/path_info.cfg +++ b/script/path_info.cfg @@ -51,6 +51,7 @@ service_source_root=( ../cmd/rpc/open_im_office/ ../cmd/rpc/open_im_organization/ ../cmd/rpc/open_im_conversation/ + ../cmd/rpc/open_im_cache/ ${msg_gateway_source_root} ${msg_transfer_source_root} ${msg_source_root} @@ -74,6 +75,7 @@ service_names=( open_im_office open_im_organization open_im_conversation + open_im_cache ${msg_gateway_name} ${msg_transfer_name} ${msg_name} diff --git a/script/start_rpc_service.sh b/script/start_rpc_service.sh index 6e60bcdcd..351bd2797 100644 --- a/script/start_rpc_service.sh +++ b/script/start_rpc_service.sh @@ -21,6 +21,7 @@ service_filename=( open_im_office open_im_organization open_im_conversation + open_im_cache ) #service config port name @@ -40,6 +41,7 @@ service_port_name=( openImOfficePort openImOrganizationPort openImConversationPort + openImCachePort ) for ((i = 0; i < ${#service_filename[*]}; i++)); do From 8f07f8e9e1bb84154985856eb8afd9cea5a1440e Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 11:19:14 +0800 Subject: [PATCH 02/12] cache rpc --- cmd/rpc/open_im_cache/main.go | 2 +- internal/api/user/user.go | 100 +++++-- internal/rpc/cache/cache.go | 23 +- pkg/proto/cache/cache.pb.go | 501 ---------------------------------- pkg/proto/cache/cache.proto | 26 +- 5 files changed, 123 insertions(+), 529 deletions(-) delete mode 100644 pkg/proto/cache/cache.pb.go diff --git a/cmd/rpc/open_im_cache/main.go b/cmd/rpc/open_im_cache/main.go index 2ab2eefa8..bc50cc28e 100644 --- a/cmd/rpc/open_im_cache/main.go +++ b/cmd/rpc/open_im_cache/main.go @@ -10,7 +10,7 @@ func main() { rpcPort := flag.Int("port", 10600, "RpcToken default listen port 10800") flag.Parse() fmt.Println("start auth rpc server, port: ", *rpcPort) - rpcServer := rpcCache.NewOfficeServer(*rpcPort) + rpcServer := rpcCache.NewCacheServer(*rpcPort) rpcServer.Run() } diff --git a/internal/api/user/user.go b/internal/api/user/user.go index af8448522..d6b733f03 100644 --- a/internal/api/user/user.go +++ b/internal/api/user/user.go @@ -8,6 +8,7 @@ import ( "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" "Open_IM/pkg/grpc-etcdv3/getcdv3" + cacheRpc "Open_IM/pkg/proto/cache" pbRelay "Open_IM/pkg/proto/relay" open_im_sdk "Open_IM/pkg/proto/sdk_ws" rpc "Open_IM/pkg/proto/user" @@ -18,7 +19,6 @@ import ( "strings" ) -//todo func GetUsersInfoFromCache(c *gin.Context) { params := api.GetUsersInfoReq{} if err := c.BindJSON(¶ms); err != nil { @@ -26,34 +26,100 @@ func GetUsersInfoFromCache(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()}) return } - req := &rpc.GetUserInfoReq{} - utils.CopyStructFields(req, ¶ms) + getUserInfoReq := &rpc.GetUserInfoReq{} + getUserInfoReq.OperationID = params.OperationID var ok bool - ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) + ok, getUserInfoReq.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), getUserInfoReq.OperationID) if !ok { - log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) + log.NewError(getUserInfoReq.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) return } - log.NewInfo(params.OperationID, "GetUserInfo args ", req.String()) - - etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) - client := rpc.NewUserClient(etcdConn) - RpcResp, err := client.GetUserInfo(context.Background(), req) + log.NewInfo(params.OperationID, "GetUserInfo args ", getUserInfoReq.String()) + reqCacheGetUserInfo := &cacheRpc.GetUserInfoReq{} + utils.CopyStructFields(reqCacheGetUserInfo, ¶ms) + var userInfoList []*open_im_sdk.UserInfo + var publicUserInfoList []*open_im_sdk.PublicUserInfo + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName) + cacheClient := cacheRpc.NewCacheClient(etcdConn) + cacheResp, err := cacheClient.GetUserInfo(context.Background(), reqCacheGetUserInfo) if err != nil { - log.NewError(req.OperationID, "GetUserInfo failed ", err.Error(), req.String()) - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"}) + log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", err.Error()) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed: " + err.Error()}) return } - var publicUserInfoList []*open_im_sdk.PublicUserInfo - for _, v := range RpcResp.UserInfoList { + if cacheResp.CommonResp.ErrCode != 0 { + log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp) + resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} + resp.Data = []map[string]interface{}{} + log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) + c.JSON(http.StatusOK, resp) + return + } + log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "cacheResp:", cacheResp.String()) + userInfoList = cacheResp.UserInfoList + var needCacheUserIDList []string + for _, userID := range reqCacheGetUserInfo.UserIDList { + isGetUserInfoFromCache := false + for _, cacheUser := range userInfoList { + if cacheUser.UserID == userID { + isGetUserInfoFromCache = true + } + } + if !isGetUserInfoFromCache { + needCacheUserIDList = append(needCacheUserIDList, userID) + } + } + if len(needCacheUserIDList) == 0 { + log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "get all userInfo from cache success") + for _, v := range userInfoList { + publicUserInfoList = append(publicUserInfoList, + &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) + } + resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} + resp.Data = jsonData.JsonDataList(resp.UserInfoList) + log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) + c.JSON(http.StatusOK, resp) + return + } + + log.NewDebug(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "need cache user list", needCacheUserIDList) + getUserInfoReq.UserIDList = needCacheUserIDList + etcdConn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) + client := rpc.NewUserClient(etcdConn) + rpcResp, err := client.GetUserInfo(context.Background(), getUserInfoReq) + if err != nil { + log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error(), getUserInfoReq.String()) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed" + err.Error()}) + return + } + if rpcResp.CommonResp.ErrCode != 0 { + log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp) + resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} + resp.Data = []map[string]interface{}{} + log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) + c.JSON(http.StatusOK, resp) + return + } + userInfoList = append(userInfoList, rpcResp.UserInfoList...) + cacheUpdateUserInfoReq := &cacheRpc.UpdateUserInfoReq{ + UserInfoList: rpcResp.UserInfoList, + OperationID: getUserInfoReq.OperationID, + } + _, err = cacheClient.UpdateUserInfo(context.Background(), cacheUpdateUserInfoReq) + if err != nil { + log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error()) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed:" + err.Error()}) + return + } + userInfoList = rpcResp.UserInfoList + for _, v := range userInfoList { publicUserInfoList = append(publicUserInfoList, &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) } - - resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} + resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} resp.Data = jsonData.JsonDataList(resp.UserInfoList) - log.NewInfo(req.OperationID, "GetUserInfo api return ", resp) + log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) c.JSON(http.StatusOK, resp) } diff --git a/internal/rpc/cache/cache.go b/internal/rpc/cache/cache.go index e172ed723..693d89cb5 100644 --- a/internal/rpc/cache/cache.go +++ b/internal/rpc/cache/cache.go @@ -23,11 +23,11 @@ type cacheServer struct { etcdAddr []string } -func NewOfficeServer(port int) *cacheServer { +func NewCacheServer(port int) *cacheServer { log.NewPrivateLog(constant.LogFileName) return &cacheServer{ rpcPort: port, - rpcRegisterName: config.Config.RpcRegisterName.OpenImOfficeName, + rpcRegisterName: config.Config.RpcRegisterName.OpenImCacheName, etcdSchema: config.Config.Etcd.EtcdSchema, etcdAddr: config.Config.Etcd.EtcdAddr, } @@ -95,9 +95,18 @@ func (s *cacheServer) UpdateUserInfo(_ context.Context, req *pbCache.UpdateUserI return resp, nil } -func (s *cacheServer) UpdateAllUserToCache(_ context.Context, req *pbCache.UpdateAllUserToCacheReq) (resp *pbCache.UpdateAllUserToCacheResp, err error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) - resp = &pbCache.UpdateAllUserToCacheResp{CommonResp: &pbCache.CommonResp{}} - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) - return resp, nil +func (s *cacheServer) GetBlackList(_ context.Context, req *pbCache.GetBlackListReq) (resp *pbCache.GetBlackListResp, err error) { + return nil, nil +} + +func (s *cacheServer) UpdateBlackList(_ context.Context, req *pbCache.UpdateBlackListReq) (resp *pbCache.UpdateBlackListResp, err error) { + return nil, nil +} + +func (s *cacheServer) GetFriendInfo(_ context.Context, req *pbCache.GetFriendInfoReq) (resp *pbCache.GetFriendInfoResp, err error) { + return nil, nil +} + +func (s *cacheServer) UpdateFriendInfo(_ context.Context, req *pbCache.UpdateFriendInfoReq) (resp *pbCache.UpdateFriendInfoResp, err error) { + return nil, nil } diff --git a/pkg/proto/cache/cache.pb.go b/pkg/proto/cache/cache.pb.go deleted file mode 100644 index 649784738..000000000 --- a/pkg/proto/cache/cache.pb.go +++ /dev/null @@ -1,501 +0,0 @@ -// Code generated by protoc-gen-go. DO NOT EDIT. -// source: cache/cache.proto - -package cache // import "./cache" - -import proto "github.com/golang/protobuf/proto" -import fmt "fmt" -import math "math" -import sdk_ws "Open_IM/pkg/proto/sdk_ws" - -import ( - context "golang.org/x/net/context" - grpc "google.golang.org/grpc" -) - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the proto package it is being compiled against. -// A compilation error at this line likely means your copy of the -// proto package needs to be updated. -const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package - -type CommonResp struct { - ErrCode int32 `protobuf:"varint,1,opt,name=errCode" json:"errCode,omitempty"` - ErrMsg string `protobuf:"bytes,2,opt,name=errMsg" json:"errMsg,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *CommonResp) Reset() { *m = CommonResp{} } -func (m *CommonResp) String() string { return proto.CompactTextString(m) } -func (*CommonResp) ProtoMessage() {} -func (*CommonResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_613af94c3da056d4, []int{0} -} -func (m *CommonResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_CommonResp.Unmarshal(m, b) -} -func (m *CommonResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_CommonResp.Marshal(b, m, deterministic) -} -func (dst *CommonResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_CommonResp.Merge(dst, src) -} -func (m *CommonResp) XXX_Size() int { - return xxx_messageInfo_CommonResp.Size(m) -} -func (m *CommonResp) XXX_DiscardUnknown() { - xxx_messageInfo_CommonResp.DiscardUnknown(m) -} - -var xxx_messageInfo_CommonResp proto.InternalMessageInfo - -func (m *CommonResp) GetErrCode() int32 { - if m != nil { - return m.ErrCode - } - return 0 -} - -func (m *CommonResp) GetErrMsg() string { - if m != nil { - return m.ErrMsg - } - return "" -} - -type GetUserInfoReq struct { - UserIDList []string `protobuf:"bytes,1,rep,name=userIDList" json:"userIDList,omitempty"` - OperationID string `protobuf:"bytes,3,opt,name=operationID" json:"operationID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *GetUserInfoReq) Reset() { *m = GetUserInfoReq{} } -func (m *GetUserInfoReq) String() string { return proto.CompactTextString(m) } -func (*GetUserInfoReq) ProtoMessage() {} -func (*GetUserInfoReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_613af94c3da056d4, []int{1} -} -func (m *GetUserInfoReq) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_GetUserInfoReq.Unmarshal(m, b) -} -func (m *GetUserInfoReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_GetUserInfoReq.Marshal(b, m, deterministic) -} -func (dst *GetUserInfoReq) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetUserInfoReq.Merge(dst, src) -} -func (m *GetUserInfoReq) XXX_Size() int { - return xxx_messageInfo_GetUserInfoReq.Size(m) -} -func (m *GetUserInfoReq) XXX_DiscardUnknown() { - xxx_messageInfo_GetUserInfoReq.DiscardUnknown(m) -} - -var xxx_messageInfo_GetUserInfoReq proto.InternalMessageInfo - -func (m *GetUserInfoReq) GetUserIDList() []string { - if m != nil { - return m.UserIDList - } - return nil -} - -func (m *GetUserInfoReq) GetOperationID() string { - if m != nil { - return m.OperationID - } - return "" -} - -type GetUserInfoResp struct { - CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` - UserInfoList []*sdk_ws.UserInfo `protobuf:"bytes,2,rep,name=UserInfoList" json:"UserInfoList,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *GetUserInfoResp) Reset() { *m = GetUserInfoResp{} } -func (m *GetUserInfoResp) String() string { return proto.CompactTextString(m) } -func (*GetUserInfoResp) ProtoMessage() {} -func (*GetUserInfoResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_613af94c3da056d4, []int{2} -} -func (m *GetUserInfoResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_GetUserInfoResp.Unmarshal(m, b) -} -func (m *GetUserInfoResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_GetUserInfoResp.Marshal(b, m, deterministic) -} -func (dst *GetUserInfoResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetUserInfoResp.Merge(dst, src) -} -func (m *GetUserInfoResp) XXX_Size() int { - return xxx_messageInfo_GetUserInfoResp.Size(m) -} -func (m *GetUserInfoResp) XXX_DiscardUnknown() { - xxx_messageInfo_GetUserInfoResp.DiscardUnknown(m) -} - -var xxx_messageInfo_GetUserInfoResp proto.InternalMessageInfo - -func (m *GetUserInfoResp) GetCommonResp() *CommonResp { - if m != nil { - return m.CommonResp - } - return nil -} - -func (m *GetUserInfoResp) GetUserInfoList() []*sdk_ws.UserInfo { - if m != nil { - return m.UserInfoList - } - return nil -} - -type UpdateUserInfoReq struct { - UserInfoList []*sdk_ws.UserInfo `protobuf:"bytes,1,rep,name=UserInfoList" json:"UserInfoList,omitempty"` - OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *UpdateUserInfoReq) Reset() { *m = UpdateUserInfoReq{} } -func (m *UpdateUserInfoReq) String() string { return proto.CompactTextString(m) } -func (*UpdateUserInfoReq) ProtoMessage() {} -func (*UpdateUserInfoReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_613af94c3da056d4, []int{3} -} -func (m *UpdateUserInfoReq) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_UpdateUserInfoReq.Unmarshal(m, b) -} -func (m *UpdateUserInfoReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_UpdateUserInfoReq.Marshal(b, m, deterministic) -} -func (dst *UpdateUserInfoReq) XXX_Merge(src proto.Message) { - xxx_messageInfo_UpdateUserInfoReq.Merge(dst, src) -} -func (m *UpdateUserInfoReq) XXX_Size() int { - return xxx_messageInfo_UpdateUserInfoReq.Size(m) -} -func (m *UpdateUserInfoReq) XXX_DiscardUnknown() { - xxx_messageInfo_UpdateUserInfoReq.DiscardUnknown(m) -} - -var xxx_messageInfo_UpdateUserInfoReq proto.InternalMessageInfo - -func (m *UpdateUserInfoReq) GetUserInfoList() []*sdk_ws.UserInfo { - if m != nil { - return m.UserInfoList - } - return nil -} - -func (m *UpdateUserInfoReq) GetOperationID() string { - if m != nil { - return m.OperationID - } - return "" -} - -type UpdateUserInfoResp struct { - CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *UpdateUserInfoResp) Reset() { *m = UpdateUserInfoResp{} } -func (m *UpdateUserInfoResp) String() string { return proto.CompactTextString(m) } -func (*UpdateUserInfoResp) ProtoMessage() {} -func (*UpdateUserInfoResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_613af94c3da056d4, []int{4} -} -func (m *UpdateUserInfoResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_UpdateUserInfoResp.Unmarshal(m, b) -} -func (m *UpdateUserInfoResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_UpdateUserInfoResp.Marshal(b, m, deterministic) -} -func (dst *UpdateUserInfoResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_UpdateUserInfoResp.Merge(dst, src) -} -func (m *UpdateUserInfoResp) XXX_Size() int { - return xxx_messageInfo_UpdateUserInfoResp.Size(m) -} -func (m *UpdateUserInfoResp) XXX_DiscardUnknown() { - xxx_messageInfo_UpdateUserInfoResp.DiscardUnknown(m) -} - -var xxx_messageInfo_UpdateUserInfoResp proto.InternalMessageInfo - -func (m *UpdateUserInfoResp) GetCommonResp() *CommonResp { - if m != nil { - return m.CommonResp - } - return nil -} - -type UpdateAllUserToCacheReq struct { - OperationID string `protobuf:"bytes,1,opt,name=operationID" json:"operationID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *UpdateAllUserToCacheReq) Reset() { *m = UpdateAllUserToCacheReq{} } -func (m *UpdateAllUserToCacheReq) String() string { return proto.CompactTextString(m) } -func (*UpdateAllUserToCacheReq) ProtoMessage() {} -func (*UpdateAllUserToCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_613af94c3da056d4, []int{5} -} -func (m *UpdateAllUserToCacheReq) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_UpdateAllUserToCacheReq.Unmarshal(m, b) -} -func (m *UpdateAllUserToCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_UpdateAllUserToCacheReq.Marshal(b, m, deterministic) -} -func (dst *UpdateAllUserToCacheReq) XXX_Merge(src proto.Message) { - xxx_messageInfo_UpdateAllUserToCacheReq.Merge(dst, src) -} -func (m *UpdateAllUserToCacheReq) XXX_Size() int { - return xxx_messageInfo_UpdateAllUserToCacheReq.Size(m) -} -func (m *UpdateAllUserToCacheReq) XXX_DiscardUnknown() { - xxx_messageInfo_UpdateAllUserToCacheReq.DiscardUnknown(m) -} - -var xxx_messageInfo_UpdateAllUserToCacheReq proto.InternalMessageInfo - -func (m *UpdateAllUserToCacheReq) GetOperationID() string { - if m != nil { - return m.OperationID - } - return "" -} - -type UpdateAllUserToCacheResp struct { - CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *UpdateAllUserToCacheResp) Reset() { *m = UpdateAllUserToCacheResp{} } -func (m *UpdateAllUserToCacheResp) String() string { return proto.CompactTextString(m) } -func (*UpdateAllUserToCacheResp) ProtoMessage() {} -func (*UpdateAllUserToCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_613af94c3da056d4, []int{6} -} -func (m *UpdateAllUserToCacheResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_UpdateAllUserToCacheResp.Unmarshal(m, b) -} -func (m *UpdateAllUserToCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_UpdateAllUserToCacheResp.Marshal(b, m, deterministic) -} -func (dst *UpdateAllUserToCacheResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_UpdateAllUserToCacheResp.Merge(dst, src) -} -func (m *UpdateAllUserToCacheResp) XXX_Size() int { - return xxx_messageInfo_UpdateAllUserToCacheResp.Size(m) -} -func (m *UpdateAllUserToCacheResp) XXX_DiscardUnknown() { - xxx_messageInfo_UpdateAllUserToCacheResp.DiscardUnknown(m) -} - -var xxx_messageInfo_UpdateAllUserToCacheResp proto.InternalMessageInfo - -func (m *UpdateAllUserToCacheResp) GetCommonResp() *CommonResp { - if m != nil { - return m.CommonResp - } - return nil -} - -func init() { - proto.RegisterType((*CommonResp)(nil), "cache.CommonResp") - proto.RegisterType((*GetUserInfoReq)(nil), "cache.GetUserInfoReq") - proto.RegisterType((*GetUserInfoResp)(nil), "cache.GetUserInfoResp") - proto.RegisterType((*UpdateUserInfoReq)(nil), "cache.UpdateUserInfoReq") - proto.RegisterType((*UpdateUserInfoResp)(nil), "cache.UpdateUserInfoResp") - proto.RegisterType((*UpdateAllUserToCacheReq)(nil), "cache.UpdateAllUserToCacheReq") - proto.RegisterType((*UpdateAllUserToCacheResp)(nil), "cache.UpdateAllUserToCacheResp") -} - -// Reference imports to suppress errors if they are not otherwise used. -var _ context.Context -var _ grpc.ClientConn - -// This is a compile-time assertion to ensure that this generated file -// is compatible with the grpc package it is being compiled against. -const _ = grpc.SupportPackageIsVersion4 - -// Client API for Cache service - -type CacheClient interface { - GetUserInfo(ctx context.Context, in *GetUserInfoReq, opts ...grpc.CallOption) (*GetUserInfoResp, error) - UpdateUserInfo(ctx context.Context, in *UpdateUserInfoReq, opts ...grpc.CallOption) (*UpdateUserInfoResp, error) - UpdateAllUserToCache(ctx context.Context, in *UpdateAllUserToCacheReq, opts ...grpc.CallOption) (*UpdateAllUserToCacheResp, error) -} - -type cacheClient struct { - cc *grpc.ClientConn -} - -func NewCacheClient(cc *grpc.ClientConn) CacheClient { - return &cacheClient{cc} -} - -func (c *cacheClient) GetUserInfo(ctx context.Context, in *GetUserInfoReq, opts ...grpc.CallOption) (*GetUserInfoResp, error) { - out := new(GetUserInfoResp) - err := grpc.Invoke(ctx, "/cache.cache/GetUserInfo", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *cacheClient) UpdateUserInfo(ctx context.Context, in *UpdateUserInfoReq, opts ...grpc.CallOption) (*UpdateUserInfoResp, error) { - out := new(UpdateUserInfoResp) - err := grpc.Invoke(ctx, "/cache.cache/UpdateUserInfo", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *cacheClient) UpdateAllUserToCache(ctx context.Context, in *UpdateAllUserToCacheReq, opts ...grpc.CallOption) (*UpdateAllUserToCacheResp, error) { - out := new(UpdateAllUserToCacheResp) - err := grpc.Invoke(ctx, "/cache.cache/UpdateAllUserToCache", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -// Server API for Cache service - -type CacheServer interface { - GetUserInfo(context.Context, *GetUserInfoReq) (*GetUserInfoResp, error) - UpdateUserInfo(context.Context, *UpdateUserInfoReq) (*UpdateUserInfoResp, error) - UpdateAllUserToCache(context.Context, *UpdateAllUserToCacheReq) (*UpdateAllUserToCacheResp, error) -} - -func RegisterCacheServer(s *grpc.Server, srv CacheServer) { - s.RegisterService(&_Cache_serviceDesc, srv) -} - -func _Cache_GetUserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetUserInfoReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CacheServer).GetUserInfo(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cache.cache/GetUserInfo", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CacheServer).GetUserInfo(ctx, req.(*GetUserInfoReq)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cache_UpdateUserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UpdateUserInfoReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CacheServer).UpdateUserInfo(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cache.cache/UpdateUserInfo", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CacheServer).UpdateUserInfo(ctx, req.(*UpdateUserInfoReq)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cache_UpdateAllUserToCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UpdateAllUserToCacheReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CacheServer).UpdateAllUserToCache(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cache.cache/UpdateAllUserToCache", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CacheServer).UpdateAllUserToCache(ctx, req.(*UpdateAllUserToCacheReq)) - } - return interceptor(ctx, in, info, handler) -} - -var _Cache_serviceDesc = grpc.ServiceDesc{ - ServiceName: "cache.cache", - HandlerType: (*CacheServer)(nil), - Methods: []grpc.MethodDesc{ - { - MethodName: "GetUserInfo", - Handler: _Cache_GetUserInfo_Handler, - }, - { - MethodName: "UpdateUserInfo", - Handler: _Cache_UpdateUserInfo_Handler, - }, - { - MethodName: "UpdateAllUserToCache", - Handler: _Cache_UpdateAllUserToCache_Handler, - }, - }, - Streams: []grpc.StreamDesc{}, - Metadata: "cache/cache.proto", -} - -func init() { proto.RegisterFile("cache/cache.proto", fileDescriptor_cache_613af94c3da056d4) } - -var fileDescriptor_cache_613af94c3da056d4 = []byte{ - // 383 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x53, 0x5d, 0x4f, 0xe2, 0x40, - 0x14, 0xcd, 0x40, 0x60, 0xc3, 0xed, 0x2e, 0x84, 0xc9, 0x2e, 0x5b, 0x6b, 0x82, 0xb5, 0x4f, 0x7d, - 0x6a, 0x23, 0x3e, 0x62, 0x34, 0x0a, 0x86, 0x90, 0x48, 0x4c, 0x26, 0x12, 0x13, 0x5f, 0x9a, 0x0a, - 0x23, 0x12, 0xa0, 0x33, 0xce, 0x54, 0xf8, 0x05, 0xfe, 0x54, 0xff, 0x87, 0xe9, 0x14, 0xb0, 0x1f, - 0x68, 0x22, 0x2f, 0x93, 0xdc, 0x8f, 0x73, 0xe6, 0x9c, 0x3b, 0x73, 0xa1, 0x3e, 0xf2, 0x47, 0xcf, - 0xd4, 0x55, 0xa7, 0xc3, 0x05, 0x0b, 0x19, 0x2e, 0xa9, 0xc0, 0x38, 0xbe, 0xe5, 0x34, 0xf0, 0xfa, - 0x03, 0x97, 0xcf, 0x26, 0xae, 0xaa, 0xb8, 0x72, 0x3c, 0xf3, 0x56, 0xd2, 0x5d, 0xc9, 0xb8, 0xd3, - 0x3a, 0x07, 0xe8, 0xb0, 0xc5, 0x82, 0x05, 0x84, 0x4a, 0x8e, 0x75, 0xf8, 0x45, 0x85, 0xe8, 0xb0, - 0x31, 0xd5, 0x91, 0x89, 0xec, 0x12, 0xd9, 0x84, 0xb8, 0x01, 0x65, 0x2a, 0xc4, 0x40, 0x4e, 0xf4, - 0x82, 0x89, 0xec, 0x0a, 0x59, 0x47, 0x16, 0x81, 0x6a, 0x8f, 0x86, 0x43, 0x49, 0x45, 0x3f, 0x78, - 0x62, 0x84, 0xbe, 0xe0, 0x26, 0xc0, 0x6b, 0x14, 0x76, 0x6f, 0xa6, 0x32, 0xd4, 0x91, 0x59, 0xb4, - 0x2b, 0x24, 0x91, 0xc1, 0x26, 0x68, 0x8c, 0x53, 0xe1, 0x87, 0x53, 0x16, 0xf4, 0xbb, 0x7a, 0x51, - 0xd1, 0x25, 0x53, 0xd6, 0x1b, 0x82, 0x5a, 0x8a, 0x54, 0x72, 0x7c, 0x02, 0x30, 0xda, 0xea, 0x54, - 0xe2, 0xb4, 0x56, 0xdd, 0x89, 0x3d, 0x7f, 0x1a, 0x20, 0x89, 0x26, 0x7c, 0x01, 0xbf, 0x37, 0x14, - 0x4a, 0x4a, 0xc1, 0x2c, 0xda, 0x5a, 0xeb, 0xd0, 0x91, 0x54, 0x2c, 0xa9, 0xf0, 0x7c, 0x3e, 0xf5, - 0xb8, 0x2f, 0xfc, 0x85, 0x74, 0xb6, 0x37, 0xa5, 0x00, 0xd6, 0x12, 0xea, 0x43, 0x3e, 0xf6, 0x43, - 0x9a, 0xb4, 0x97, 0x65, 0x45, 0x3f, 0x64, 0xcd, 0xfa, 0x2f, 0xe4, 0xfd, 0xf7, 0x00, 0x67, 0xef, - 0xdd, 0x6b, 0x02, 0x56, 0x1b, 0xfe, 0xc7, 0x44, 0x97, 0xf3, 0x79, 0xc4, 0x75, 0xc7, 0x3a, 0x51, - 0x7b, 0x64, 0x23, 0xa3, 0x02, 0xe5, 0x55, 0x0c, 0x40, 0xdf, 0x0d, 0xde, 0x4b, 0x4b, 0xeb, 0x1d, - 0x41, 0xfc, 0x2b, 0xf1, 0x19, 0x68, 0x89, 0xd7, 0xc5, 0xff, 0xd6, 0xb8, 0xf4, 0x37, 0x32, 0x1a, - 0xbb, 0xd2, 0x92, 0xe3, 0x6b, 0xa8, 0xa6, 0x87, 0x83, 0xf5, 0x75, 0x67, 0xee, 0xad, 0x8c, 0x83, - 0x2f, 0x2a, 0x92, 0xe3, 0x7b, 0xf8, 0xbb, 0xcb, 0x1d, 0x6e, 0xa6, 0x20, 0xb9, 0xb9, 0x19, 0x47, - 0xdf, 0xd6, 0x25, 0xbf, 0xaa, 0x3d, 0xfc, 0x71, 0xe2, 0x5d, 0x6c, 0xab, 0xf3, 0xb1, 0xac, 0x16, - 0xed, 0xf4, 0x23, 0x00, 0x00, 0xff, 0xff, 0x14, 0x24, 0x83, 0x9c, 0xa7, 0x03, 0x00, 0x00, -} diff --git a/pkg/proto/cache/cache.proto b/pkg/proto/cache/cache.proto index c618c20f8..e5da4efa7 100644 --- a/pkg/proto/cache/cache.proto +++ b/pkg/proto/cache/cache.proto @@ -28,13 +28,32 @@ message UpdateUserInfoResp{ CommonResp commonResp = 1; } - message GetFriendInfoReq { - + string userID = 1; + string operationID = 2; } message GetFriendInfoResp { + repeated server_api_params.FriendInfo friendInfoList = 1; + CommonResp commonResp = 2; +} +message UpdateBlackListReq { + repeated server_api_params.BlackInfo blackList = 1; + string operationID = 2; +} + +message UpdateBlackListResp { + CommonResp commonResp = 1; +} + +message GetBlackListReq { + string userID = 1; + string operationID = 2; +} + +message GetBlackListResp { + repeated server_api_params.BlackInfo blackList = 1; } @@ -52,7 +71,8 @@ service cache{ rpc UpdateUserInfo(UpdateUserInfoReq) returns(UpdateUserInfoResp); rpc GetFriendInfo(GetFriendInfoReq) returns(GetFriendInfoResp); rpc UpdateFriendInfo(UpdateFriendInfoReq) returns(UpdateFriendInfoResp); - rpc + rpc UpdateBlackList(UpdateBlackListReq) returns(UpdateBlackListResp); + rpc GetBlackList(GetBlackListReq) returns(GetBlackListResp); } From f662defcf9d5a1ff60cb61edd0738a16d9599d20 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 11:19:21 +0800 Subject: [PATCH 03/12] cache rpc --- pkg/proto/cache/cache.pb.go | 883 ++++++++++++++++++++++++++++++++++++ 1 file changed, 883 insertions(+) create mode 100644 pkg/proto/cache/cache.pb.go diff --git a/pkg/proto/cache/cache.pb.go b/pkg/proto/cache/cache.pb.go new file mode 100644 index 000000000..430ec0c78 --- /dev/null +++ b/pkg/proto/cache/cache.pb.go @@ -0,0 +1,883 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// source: cache/cache.proto + +package cache // import "./cache" + +import proto "github.com/golang/protobuf/proto" +import fmt "fmt" +import math "math" +import sdk_ws "Open_IM/pkg/proto/sdk_ws" + +import ( + context "golang.org/x/net/context" + grpc "google.golang.org/grpc" +) + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the proto package it is being compiled against. +// A compilation error at this line likely means your copy of the +// proto package needs to be updated. +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package + +type CommonResp struct { + ErrCode int32 `protobuf:"varint,1,opt,name=errCode" json:"errCode,omitempty"` + ErrMsg string `protobuf:"bytes,2,opt,name=errMsg" json:"errMsg,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *CommonResp) Reset() { *m = CommonResp{} } +func (m *CommonResp) String() string { return proto.CompactTextString(m) } +func (*CommonResp) ProtoMessage() {} +func (*CommonResp) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{0} +} +func (m *CommonResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_CommonResp.Unmarshal(m, b) +} +func (m *CommonResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_CommonResp.Marshal(b, m, deterministic) +} +func (dst *CommonResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_CommonResp.Merge(dst, src) +} +func (m *CommonResp) XXX_Size() int { + return xxx_messageInfo_CommonResp.Size(m) +} +func (m *CommonResp) XXX_DiscardUnknown() { + xxx_messageInfo_CommonResp.DiscardUnknown(m) +} + +var xxx_messageInfo_CommonResp proto.InternalMessageInfo + +func (m *CommonResp) GetErrCode() int32 { + if m != nil { + return m.ErrCode + } + return 0 +} + +func (m *CommonResp) GetErrMsg() string { + if m != nil { + return m.ErrMsg + } + return "" +} + +type GetUserInfoReq struct { + UserIDList []string `protobuf:"bytes,1,rep,name=userIDList" json:"userIDList,omitempty"` + OperationID string `protobuf:"bytes,3,opt,name=operationID" json:"operationID,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetUserInfoReq) Reset() { *m = GetUserInfoReq{} } +func (m *GetUserInfoReq) String() string { return proto.CompactTextString(m) } +func (*GetUserInfoReq) ProtoMessage() {} +func (*GetUserInfoReq) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{1} +} +func (m *GetUserInfoReq) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetUserInfoReq.Unmarshal(m, b) +} +func (m *GetUserInfoReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetUserInfoReq.Marshal(b, m, deterministic) +} +func (dst *GetUserInfoReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetUserInfoReq.Merge(dst, src) +} +func (m *GetUserInfoReq) XXX_Size() int { + return xxx_messageInfo_GetUserInfoReq.Size(m) +} +func (m *GetUserInfoReq) XXX_DiscardUnknown() { + xxx_messageInfo_GetUserInfoReq.DiscardUnknown(m) +} + +var xxx_messageInfo_GetUserInfoReq proto.InternalMessageInfo + +func (m *GetUserInfoReq) GetUserIDList() []string { + if m != nil { + return m.UserIDList + } + return nil +} + +func (m *GetUserInfoReq) GetOperationID() string { + if m != nil { + return m.OperationID + } + return "" +} + +type GetUserInfoResp struct { + CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` + UserInfoList []*sdk_ws.UserInfo `protobuf:"bytes,2,rep,name=userInfoList" json:"userInfoList,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetUserInfoResp) Reset() { *m = GetUserInfoResp{} } +func (m *GetUserInfoResp) String() string { return proto.CompactTextString(m) } +func (*GetUserInfoResp) ProtoMessage() {} +func (*GetUserInfoResp) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{2} +} +func (m *GetUserInfoResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetUserInfoResp.Unmarshal(m, b) +} +func (m *GetUserInfoResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetUserInfoResp.Marshal(b, m, deterministic) +} +func (dst *GetUserInfoResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetUserInfoResp.Merge(dst, src) +} +func (m *GetUserInfoResp) XXX_Size() int { + return xxx_messageInfo_GetUserInfoResp.Size(m) +} +func (m *GetUserInfoResp) XXX_DiscardUnknown() { + xxx_messageInfo_GetUserInfoResp.DiscardUnknown(m) +} + +var xxx_messageInfo_GetUserInfoResp proto.InternalMessageInfo + +func (m *GetUserInfoResp) GetCommonResp() *CommonResp { + if m != nil { + return m.CommonResp + } + return nil +} + +func (m *GetUserInfoResp) GetUserInfoList() []*sdk_ws.UserInfo { + if m != nil { + return m.UserInfoList + } + return nil +} + +type UpdateUserInfoReq struct { + UserInfoList []*sdk_ws.UserInfo `protobuf:"bytes,1,rep,name=userInfoList" json:"userInfoList,omitempty"` + OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateUserInfoReq) Reset() { *m = UpdateUserInfoReq{} } +func (m *UpdateUserInfoReq) String() string { return proto.CompactTextString(m) } +func (*UpdateUserInfoReq) ProtoMessage() {} +func (*UpdateUserInfoReq) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{3} +} +func (m *UpdateUserInfoReq) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateUserInfoReq.Unmarshal(m, b) +} +func (m *UpdateUserInfoReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateUserInfoReq.Marshal(b, m, deterministic) +} +func (dst *UpdateUserInfoReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateUserInfoReq.Merge(dst, src) +} +func (m *UpdateUserInfoReq) XXX_Size() int { + return xxx_messageInfo_UpdateUserInfoReq.Size(m) +} +func (m *UpdateUserInfoReq) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateUserInfoReq.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateUserInfoReq proto.InternalMessageInfo + +func (m *UpdateUserInfoReq) GetUserInfoList() []*sdk_ws.UserInfo { + if m != nil { + return m.UserInfoList + } + return nil +} + +func (m *UpdateUserInfoReq) GetOperationID() string { + if m != nil { + return m.OperationID + } + return "" +} + +type UpdateUserInfoResp struct { + CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateUserInfoResp) Reset() { *m = UpdateUserInfoResp{} } +func (m *UpdateUserInfoResp) String() string { return proto.CompactTextString(m) } +func (*UpdateUserInfoResp) ProtoMessage() {} +func (*UpdateUserInfoResp) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{4} +} +func (m *UpdateUserInfoResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateUserInfoResp.Unmarshal(m, b) +} +func (m *UpdateUserInfoResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateUserInfoResp.Marshal(b, m, deterministic) +} +func (dst *UpdateUserInfoResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateUserInfoResp.Merge(dst, src) +} +func (m *UpdateUserInfoResp) XXX_Size() int { + return xxx_messageInfo_UpdateUserInfoResp.Size(m) +} +func (m *UpdateUserInfoResp) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateUserInfoResp.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateUserInfoResp proto.InternalMessageInfo + +func (m *UpdateUserInfoResp) GetCommonResp() *CommonResp { + if m != nil { + return m.CommonResp + } + return nil +} + +type GetFriendInfoReq struct { + UserID string `protobuf:"bytes,1,opt,name=userID" json:"userID,omitempty"` + OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetFriendInfoReq) Reset() { *m = GetFriendInfoReq{} } +func (m *GetFriendInfoReq) String() string { return proto.CompactTextString(m) } +func (*GetFriendInfoReq) ProtoMessage() {} +func (*GetFriendInfoReq) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{5} +} +func (m *GetFriendInfoReq) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetFriendInfoReq.Unmarshal(m, b) +} +func (m *GetFriendInfoReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetFriendInfoReq.Marshal(b, m, deterministic) +} +func (dst *GetFriendInfoReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetFriendInfoReq.Merge(dst, src) +} +func (m *GetFriendInfoReq) XXX_Size() int { + return xxx_messageInfo_GetFriendInfoReq.Size(m) +} +func (m *GetFriendInfoReq) XXX_DiscardUnknown() { + xxx_messageInfo_GetFriendInfoReq.DiscardUnknown(m) +} + +var xxx_messageInfo_GetFriendInfoReq proto.InternalMessageInfo + +func (m *GetFriendInfoReq) GetUserID() string { + if m != nil { + return m.UserID + } + return "" +} + +func (m *GetFriendInfoReq) GetOperationID() string { + if m != nil { + return m.OperationID + } + return "" +} + +type GetFriendInfoResp struct { + FriendInfoList []*sdk_ws.FriendInfo `protobuf:"bytes,1,rep,name=friendInfoList" json:"friendInfoList,omitempty"` + CommonResp *CommonResp `protobuf:"bytes,2,opt,name=commonResp" json:"commonResp,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetFriendInfoResp) Reset() { *m = GetFriendInfoResp{} } +func (m *GetFriendInfoResp) String() string { return proto.CompactTextString(m) } +func (*GetFriendInfoResp) ProtoMessage() {} +func (*GetFriendInfoResp) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{6} +} +func (m *GetFriendInfoResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetFriendInfoResp.Unmarshal(m, b) +} +func (m *GetFriendInfoResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetFriendInfoResp.Marshal(b, m, deterministic) +} +func (dst *GetFriendInfoResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetFriendInfoResp.Merge(dst, src) +} +func (m *GetFriendInfoResp) XXX_Size() int { + return xxx_messageInfo_GetFriendInfoResp.Size(m) +} +func (m *GetFriendInfoResp) XXX_DiscardUnknown() { + xxx_messageInfo_GetFriendInfoResp.DiscardUnknown(m) +} + +var xxx_messageInfo_GetFriendInfoResp proto.InternalMessageInfo + +func (m *GetFriendInfoResp) GetFriendInfoList() []*sdk_ws.FriendInfo { + if m != nil { + return m.FriendInfoList + } + return nil +} + +func (m *GetFriendInfoResp) GetCommonResp() *CommonResp { + if m != nil { + return m.CommonResp + } + return nil +} + +type UpdateBlackListReq struct { + BlackList []*sdk_ws.BlackInfo `protobuf:"bytes,1,rep,name=blackList" json:"blackList,omitempty"` + OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateBlackListReq) Reset() { *m = UpdateBlackListReq{} } +func (m *UpdateBlackListReq) String() string { return proto.CompactTextString(m) } +func (*UpdateBlackListReq) ProtoMessage() {} +func (*UpdateBlackListReq) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{7} +} +func (m *UpdateBlackListReq) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateBlackListReq.Unmarshal(m, b) +} +func (m *UpdateBlackListReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateBlackListReq.Marshal(b, m, deterministic) +} +func (dst *UpdateBlackListReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateBlackListReq.Merge(dst, src) +} +func (m *UpdateBlackListReq) XXX_Size() int { + return xxx_messageInfo_UpdateBlackListReq.Size(m) +} +func (m *UpdateBlackListReq) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateBlackListReq.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateBlackListReq proto.InternalMessageInfo + +func (m *UpdateBlackListReq) GetBlackList() []*sdk_ws.BlackInfo { + if m != nil { + return m.BlackList + } + return nil +} + +func (m *UpdateBlackListReq) GetOperationID() string { + if m != nil { + return m.OperationID + } + return "" +} + +type UpdateBlackListResp struct { + CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateBlackListResp) Reset() { *m = UpdateBlackListResp{} } +func (m *UpdateBlackListResp) String() string { return proto.CompactTextString(m) } +func (*UpdateBlackListResp) ProtoMessage() {} +func (*UpdateBlackListResp) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{8} +} +func (m *UpdateBlackListResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateBlackListResp.Unmarshal(m, b) +} +func (m *UpdateBlackListResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateBlackListResp.Marshal(b, m, deterministic) +} +func (dst *UpdateBlackListResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateBlackListResp.Merge(dst, src) +} +func (m *UpdateBlackListResp) XXX_Size() int { + return xxx_messageInfo_UpdateBlackListResp.Size(m) +} +func (m *UpdateBlackListResp) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateBlackListResp.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateBlackListResp proto.InternalMessageInfo + +func (m *UpdateBlackListResp) GetCommonResp() *CommonResp { + if m != nil { + return m.CommonResp + } + return nil +} + +type GetBlackListReq struct { + UserID string `protobuf:"bytes,1,opt,name=userID" json:"userID,omitempty"` + OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetBlackListReq) Reset() { *m = GetBlackListReq{} } +func (m *GetBlackListReq) String() string { return proto.CompactTextString(m) } +func (*GetBlackListReq) ProtoMessage() {} +func (*GetBlackListReq) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{9} +} +func (m *GetBlackListReq) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetBlackListReq.Unmarshal(m, b) +} +func (m *GetBlackListReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetBlackListReq.Marshal(b, m, deterministic) +} +func (dst *GetBlackListReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetBlackListReq.Merge(dst, src) +} +func (m *GetBlackListReq) XXX_Size() int { + return xxx_messageInfo_GetBlackListReq.Size(m) +} +func (m *GetBlackListReq) XXX_DiscardUnknown() { + xxx_messageInfo_GetBlackListReq.DiscardUnknown(m) +} + +var xxx_messageInfo_GetBlackListReq proto.InternalMessageInfo + +func (m *GetBlackListReq) GetUserID() string { + if m != nil { + return m.UserID + } + return "" +} + +func (m *GetBlackListReq) GetOperationID() string { + if m != nil { + return m.OperationID + } + return "" +} + +type GetBlackListResp struct { + BlackList []*sdk_ws.BlackInfo `protobuf:"bytes,1,rep,name=blackList" json:"blackList,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *GetBlackListResp) Reset() { *m = GetBlackListResp{} } +func (m *GetBlackListResp) String() string { return proto.CompactTextString(m) } +func (*GetBlackListResp) ProtoMessage() {} +func (*GetBlackListResp) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{10} +} +func (m *GetBlackListResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_GetBlackListResp.Unmarshal(m, b) +} +func (m *GetBlackListResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_GetBlackListResp.Marshal(b, m, deterministic) +} +func (dst *GetBlackListResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_GetBlackListResp.Merge(dst, src) +} +func (m *GetBlackListResp) XXX_Size() int { + return xxx_messageInfo_GetBlackListResp.Size(m) +} +func (m *GetBlackListResp) XXX_DiscardUnknown() { + xxx_messageInfo_GetBlackListResp.DiscardUnknown(m) +} + +var xxx_messageInfo_GetBlackListResp proto.InternalMessageInfo + +func (m *GetBlackListResp) GetBlackList() []*sdk_ws.BlackInfo { + if m != nil { + return m.BlackList + } + return nil +} + +type UpdateFriendInfoReq struct { + FriendInfoList []*sdk_ws.FriendInfo `protobuf:"bytes,1,rep,name=friendInfoList" json:"friendInfoList,omitempty"` + OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateFriendInfoReq) Reset() { *m = UpdateFriendInfoReq{} } +func (m *UpdateFriendInfoReq) String() string { return proto.CompactTextString(m) } +func (*UpdateFriendInfoReq) ProtoMessage() {} +func (*UpdateFriendInfoReq) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{11} +} +func (m *UpdateFriendInfoReq) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateFriendInfoReq.Unmarshal(m, b) +} +func (m *UpdateFriendInfoReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateFriendInfoReq.Marshal(b, m, deterministic) +} +func (dst *UpdateFriendInfoReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateFriendInfoReq.Merge(dst, src) +} +func (m *UpdateFriendInfoReq) XXX_Size() int { + return xxx_messageInfo_UpdateFriendInfoReq.Size(m) +} +func (m *UpdateFriendInfoReq) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateFriendInfoReq.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateFriendInfoReq proto.InternalMessageInfo + +func (m *UpdateFriendInfoReq) GetFriendInfoList() []*sdk_ws.FriendInfo { + if m != nil { + return m.FriendInfoList + } + return nil +} + +func (m *UpdateFriendInfoReq) GetOperationID() string { + if m != nil { + return m.OperationID + } + return "" +} + +type UpdateFriendInfoResp struct { + CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *UpdateFriendInfoResp) Reset() { *m = UpdateFriendInfoResp{} } +func (m *UpdateFriendInfoResp) String() string { return proto.CompactTextString(m) } +func (*UpdateFriendInfoResp) ProtoMessage() {} +func (*UpdateFriendInfoResp) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_c95b22de9c135769, []int{12} +} +func (m *UpdateFriendInfoResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_UpdateFriendInfoResp.Unmarshal(m, b) +} +func (m *UpdateFriendInfoResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_UpdateFriendInfoResp.Marshal(b, m, deterministic) +} +func (dst *UpdateFriendInfoResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_UpdateFriendInfoResp.Merge(dst, src) +} +func (m *UpdateFriendInfoResp) XXX_Size() int { + return xxx_messageInfo_UpdateFriendInfoResp.Size(m) +} +func (m *UpdateFriendInfoResp) XXX_DiscardUnknown() { + xxx_messageInfo_UpdateFriendInfoResp.DiscardUnknown(m) +} + +var xxx_messageInfo_UpdateFriendInfoResp proto.InternalMessageInfo + +func (m *UpdateFriendInfoResp) GetCommonResp() *CommonResp { + if m != nil { + return m.CommonResp + } + return nil +} + +func init() { + proto.RegisterType((*CommonResp)(nil), "cache.CommonResp") + proto.RegisterType((*GetUserInfoReq)(nil), "cache.GetUserInfoReq") + proto.RegisterType((*GetUserInfoResp)(nil), "cache.GetUserInfoResp") + proto.RegisterType((*UpdateUserInfoReq)(nil), "cache.UpdateUserInfoReq") + proto.RegisterType((*UpdateUserInfoResp)(nil), "cache.UpdateUserInfoResp") + proto.RegisterType((*GetFriendInfoReq)(nil), "cache.GetFriendInfoReq") + proto.RegisterType((*GetFriendInfoResp)(nil), "cache.GetFriendInfoResp") + proto.RegisterType((*UpdateBlackListReq)(nil), "cache.UpdateBlackListReq") + proto.RegisterType((*UpdateBlackListResp)(nil), "cache.UpdateBlackListResp") + proto.RegisterType((*GetBlackListReq)(nil), "cache.GetBlackListReq") + proto.RegisterType((*GetBlackListResp)(nil), "cache.GetBlackListResp") + proto.RegisterType((*UpdateFriendInfoReq)(nil), "cache.UpdateFriendInfoReq") + proto.RegisterType((*UpdateFriendInfoResp)(nil), "cache.UpdateFriendInfoResp") +} + +// Reference imports to suppress errors if they are not otherwise used. +var _ context.Context +var _ grpc.ClientConn + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +const _ = grpc.SupportPackageIsVersion4 + +// Client API for Cache service + +type CacheClient interface { + GetUserInfo(ctx context.Context, in *GetUserInfoReq, opts ...grpc.CallOption) (*GetUserInfoResp, error) + UpdateUserInfo(ctx context.Context, in *UpdateUserInfoReq, opts ...grpc.CallOption) (*UpdateUserInfoResp, error) + GetFriendInfo(ctx context.Context, in *GetFriendInfoReq, opts ...grpc.CallOption) (*GetFriendInfoResp, error) + UpdateFriendInfo(ctx context.Context, in *UpdateFriendInfoReq, opts ...grpc.CallOption) (*UpdateFriendInfoResp, error) + UpdateBlackList(ctx context.Context, in *UpdateBlackListReq, opts ...grpc.CallOption) (*UpdateBlackListResp, error) + GetBlackList(ctx context.Context, in *GetBlackListReq, opts ...grpc.CallOption) (*GetBlackListResp, error) +} + +type cacheClient struct { + cc *grpc.ClientConn +} + +func NewCacheClient(cc *grpc.ClientConn) CacheClient { + return &cacheClient{cc} +} + +func (c *cacheClient) GetUserInfo(ctx context.Context, in *GetUserInfoReq, opts ...grpc.CallOption) (*GetUserInfoResp, error) { + out := new(GetUserInfoResp) + err := grpc.Invoke(ctx, "/cache.cache/GetUserInfo", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *cacheClient) UpdateUserInfo(ctx context.Context, in *UpdateUserInfoReq, opts ...grpc.CallOption) (*UpdateUserInfoResp, error) { + out := new(UpdateUserInfoResp) + err := grpc.Invoke(ctx, "/cache.cache/UpdateUserInfo", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *cacheClient) GetFriendInfo(ctx context.Context, in *GetFriendInfoReq, opts ...grpc.CallOption) (*GetFriendInfoResp, error) { + out := new(GetFriendInfoResp) + err := grpc.Invoke(ctx, "/cache.cache/GetFriendInfo", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *cacheClient) UpdateFriendInfo(ctx context.Context, in *UpdateFriendInfoReq, opts ...grpc.CallOption) (*UpdateFriendInfoResp, error) { + out := new(UpdateFriendInfoResp) + err := grpc.Invoke(ctx, "/cache.cache/UpdateFriendInfo", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *cacheClient) UpdateBlackList(ctx context.Context, in *UpdateBlackListReq, opts ...grpc.CallOption) (*UpdateBlackListResp, error) { + out := new(UpdateBlackListResp) + err := grpc.Invoke(ctx, "/cache.cache/UpdateBlackList", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *cacheClient) GetBlackList(ctx context.Context, in *GetBlackListReq, opts ...grpc.CallOption) (*GetBlackListResp, error) { + out := new(GetBlackListResp) + err := grpc.Invoke(ctx, "/cache.cache/GetBlackList", in, out, c.cc, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// Server API for Cache service + +type CacheServer interface { + GetUserInfo(context.Context, *GetUserInfoReq) (*GetUserInfoResp, error) + UpdateUserInfo(context.Context, *UpdateUserInfoReq) (*UpdateUserInfoResp, error) + GetFriendInfo(context.Context, *GetFriendInfoReq) (*GetFriendInfoResp, error) + UpdateFriendInfo(context.Context, *UpdateFriendInfoReq) (*UpdateFriendInfoResp, error) + UpdateBlackList(context.Context, *UpdateBlackListReq) (*UpdateBlackListResp, error) + GetBlackList(context.Context, *GetBlackListReq) (*GetBlackListResp, error) +} + +func RegisterCacheServer(s *grpc.Server, srv CacheServer) { + s.RegisterService(&_Cache_serviceDesc, srv) +} + +func _Cache_GetUserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetUserInfoReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CacheServer).GetUserInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cache.cache/GetUserInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CacheServer).GetUserInfo(ctx, req.(*GetUserInfoReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Cache_UpdateUserInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateUserInfoReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CacheServer).UpdateUserInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cache.cache/UpdateUserInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CacheServer).UpdateUserInfo(ctx, req.(*UpdateUserInfoReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Cache_GetFriendInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetFriendInfoReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CacheServer).GetFriendInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cache.cache/GetFriendInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CacheServer).GetFriendInfo(ctx, req.(*GetFriendInfoReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Cache_UpdateFriendInfo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateFriendInfoReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CacheServer).UpdateFriendInfo(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cache.cache/UpdateFriendInfo", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CacheServer).UpdateFriendInfo(ctx, req.(*UpdateFriendInfoReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Cache_UpdateBlackList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(UpdateBlackListReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CacheServer).UpdateBlackList(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cache.cache/UpdateBlackList", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CacheServer).UpdateBlackList(ctx, req.(*UpdateBlackListReq)) + } + return interceptor(ctx, in, info, handler) +} + +func _Cache_GetBlackList_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBlackListReq) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CacheServer).GetBlackList(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cache.cache/GetBlackList", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CacheServer).GetBlackList(ctx, req.(*GetBlackListReq)) + } + return interceptor(ctx, in, info, handler) +} + +var _Cache_serviceDesc = grpc.ServiceDesc{ + ServiceName: "cache.cache", + HandlerType: (*CacheServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetUserInfo", + Handler: _Cache_GetUserInfo_Handler, + }, + { + MethodName: "UpdateUserInfo", + Handler: _Cache_UpdateUserInfo_Handler, + }, + { + MethodName: "GetFriendInfo", + Handler: _Cache_GetFriendInfo_Handler, + }, + { + MethodName: "UpdateFriendInfo", + Handler: _Cache_UpdateFriendInfo_Handler, + }, + { + MethodName: "UpdateBlackList", + Handler: _Cache_UpdateBlackList_Handler, + }, + { + MethodName: "GetBlackList", + Handler: _Cache_GetBlackList_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "cache/cache.proto", +} + +func init() { proto.RegisterFile("cache/cache.proto", fileDescriptor_cache_c95b22de9c135769) } + +var fileDescriptor_cache_c95b22de9c135769 = []byte{ + // 527 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xac, 0x55, 0x4d, 0x6f, 0xd3, 0x40, + 0x10, 0x95, 0x13, 0x35, 0x28, 0x13, 0xda, 0x34, 0x03, 0xa4, 0xc6, 0x05, 0x64, 0x7c, 0xca, 0xc9, + 0x16, 0xe1, 0x06, 0x08, 0xa4, 0xb4, 0x90, 0x46, 0x6d, 0x41, 0x5a, 0xa9, 0x17, 0x2e, 0x91, 0x9b, + 0x6c, 0x4b, 0x14, 0xe2, 0x5d, 0x76, 0xdd, 0xf6, 0xc6, 0x8d, 0x23, 0xff, 0x83, 0x9f, 0x89, 0xb2, + 0xb6, 0x93, 0xdd, 0x8d, 0x23, 0x42, 0xe0, 0x62, 0x69, 0xf6, 0xe3, 0xcd, 0x7b, 0x6f, 0xc6, 0xb3, + 0xd0, 0x1a, 0xc5, 0xa3, 0x2f, 0x34, 0x52, 0xdf, 0x90, 0x0b, 0x96, 0x32, 0xdc, 0x51, 0x81, 0xf7, + 0xfc, 0x13, 0xa7, 0xc9, 0x70, 0x70, 0x1e, 0xf1, 0xe9, 0x75, 0xa4, 0x76, 0x22, 0x39, 0x9e, 0x0e, + 0xef, 0x64, 0x74, 0x27, 0xb3, 0x93, 0xc1, 0x5b, 0x80, 0x23, 0x36, 0x9b, 0xb1, 0x84, 0x50, 0xc9, + 0xd1, 0x85, 0x7b, 0x54, 0x88, 0x23, 0x36, 0xa6, 0xae, 0xe3, 0x3b, 0x9d, 0x1d, 0x52, 0x84, 0xd8, + 0x86, 0x1a, 0x15, 0xe2, 0x5c, 0x5e, 0xbb, 0x15, 0xdf, 0xe9, 0xd4, 0x49, 0x1e, 0x05, 0x04, 0xf6, + 0xfa, 0x34, 0xbd, 0x90, 0x54, 0x0c, 0x92, 0x2b, 0x46, 0xe8, 0x37, 0x7c, 0x06, 0x70, 0x33, 0x0f, + 0x8f, 0xcf, 0x26, 0x32, 0x75, 0x1d, 0xbf, 0xda, 0xa9, 0x13, 0x6d, 0x05, 0x7d, 0x68, 0x30, 0x4e, + 0x45, 0x9c, 0x4e, 0x58, 0x32, 0x38, 0x76, 0xab, 0x0a, 0x4e, 0x5f, 0x0a, 0x7e, 0x38, 0xd0, 0x34, + 0x40, 0x25, 0xc7, 0x17, 0x00, 0xa3, 0x05, 0x4f, 0x45, 0xae, 0xd1, 0x6d, 0x85, 0x99, 0xe6, 0xa5, + 0x00, 0xa2, 0x1d, 0xc2, 0x77, 0x70, 0xff, 0x26, 0x87, 0x50, 0x54, 0x2a, 0x7e, 0xb5, 0xd3, 0xe8, + 0x1e, 0x86, 0x92, 0x8a, 0x5b, 0x2a, 0x86, 0x31, 0x9f, 0x0c, 0x79, 0x2c, 0xe2, 0x99, 0x0c, 0x17, + 0x99, 0x8c, 0x0b, 0xc1, 0x2d, 0xb4, 0x2e, 0xf8, 0x38, 0x4e, 0xa9, 0x2e, 0xcf, 0x46, 0x75, 0xfe, + 0x12, 0xd5, 0xd6, 0x5f, 0x59, 0xd5, 0xdf, 0x07, 0xb4, 0xf3, 0x6e, 0xe5, 0x40, 0x70, 0x06, 0xfb, + 0x7d, 0x9a, 0x7e, 0x10, 0x13, 0x9a, 0x8c, 0x0b, 0xfe, 0x6d, 0xa8, 0x65, 0xc5, 0x50, 0x10, 0x75, + 0x92, 0x47, 0x1b, 0xd0, 0xfa, 0xe9, 0x40, 0xcb, 0x82, 0x93, 0x1c, 0xdf, 0xc3, 0xde, 0xd5, 0x62, + 0x45, 0x73, 0xe4, 0x69, 0x89, 0x23, 0xda, 0x55, 0xeb, 0x92, 0xa5, 0xae, 0xb2, 0x89, 0x3a, 0x51, + 0xd8, 0xd4, 0xfb, 0x1a, 0x8f, 0xa6, 0x73, 0x94, 0xb9, 0xbe, 0x57, 0x50, 0xbf, 0x2c, 0xe2, 0x9c, + 0xca, 0x93, 0x12, 0x2a, 0xea, 0x8e, 0x62, 0xb2, 0x3c, 0xbe, 0x81, 0x07, 0x27, 0xf0, 0x60, 0x25, + 0xe7, 0x76, 0xb5, 0x39, 0x55, 0x3d, 0x6e, 0x50, 0xdf, 0xbe, 0x34, 0x1f, 0x55, 0xa1, 0x4d, 0x4e, + 0xff, 0x60, 0x44, 0xf0, 0xbd, 0x90, 0x69, 0xf6, 0xce, 0x7f, 0xaa, 0xf5, 0x9f, 0xf5, 0x0c, 0xe0, + 0xe1, 0x6a, 0xfe, 0xad, 0x7c, 0xee, 0xfe, 0xaa, 0x42, 0x36, 0x0d, 0xf1, 0x0d, 0x34, 0xb4, 0xa9, + 0x82, 0x8f, 0xf2, 0x7b, 0xe6, 0xf8, 0xf2, 0xda, 0x65, 0xcb, 0x59, 0x9f, 0x9b, 0x3f, 0x25, 0xba, + 0xf9, 0xc9, 0x95, 0x19, 0xe1, 0x3d, 0x5e, 0xb3, 0x23, 0x39, 0xf6, 0x60, 0xd7, 0xf8, 0x87, 0xf0, + 0x60, 0x99, 0xcf, 0x30, 0xdb, 0x73, 0xcb, 0x37, 0x24, 0xc7, 0x53, 0xd8, 0xb7, 0xdd, 0x41, 0xcf, + 0x48, 0x69, 0x22, 0x1d, 0xae, 0xdd, 0x93, 0x1c, 0x4f, 0xa0, 0x69, 0x75, 0x34, 0x9a, 0xf4, 0xf5, + 0x16, 0xf5, 0xbc, 0x75, 0x5b, 0xd9, 0xbc, 0xd5, 0x9b, 0x10, 0x35, 0x27, 0x0d, 0x8c, 0x83, 0xd2, + 0x75, 0xc9, 0x7b, 0xcd, 0xcf, 0xbb, 0x61, 0xf6, 0x8c, 0xbd, 0x56, 0xdf, 0xcb, 0x9a, 0x7a, 0xa3, + 0x5e, 0xfe, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xb4, 0x17, 0x6d, 0x42, 0xe2, 0x06, 0x00, 0x00, +} From 16264065574976e68dba60ed3b09f87a359070e8 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 14:13:36 +0800 Subject: [PATCH 04/12] cache rpc --- internal/rpc/cache/cache.go | 6 ++++++ internal/rpc/office/office.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/rpc/cache/cache.go b/internal/rpc/cache/cache.go index 693d89cb5..8aabca616 100644 --- a/internal/rpc/cache/cache.go +++ b/internal/rpc/cache/cache.go @@ -96,10 +96,16 @@ func (s *cacheServer) UpdateUserInfo(_ context.Context, req *pbCache.UpdateUserI } func (s *cacheServer) GetBlackList(_ context.Context, req *pbCache.GetBlackListReq) (resp *pbCache.GetBlackListResp, err error) { + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) + + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) return nil, nil } func (s *cacheServer) UpdateBlackList(_ context.Context, req *pbCache.UpdateBlackListReq) (resp *pbCache.UpdateBlackListResp, err error) { + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) + + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) return nil, nil } diff --git a/internal/rpc/office/office.go b/internal/rpc/office/office.go index 4862e4d07..19b21a8ec 100644 --- a/internal/rpc/office/office.go +++ b/internal/rpc/office/office.go @@ -305,7 +305,7 @@ func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.Crea UserName: createUser.Nickname, CreateTime: workMoment.CreateTime, } - msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, atUser.UserID, workMomentNotificationMsg) + msg.WorkMomentSendNotification(req.OperationID, atUser.UserID, atUser.UserID, workMomentNotificationMsg) } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil From 69c46f684ff44d750f79d5e97e6407ae6d5bcb6e Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 14:38:11 +0800 Subject: [PATCH 05/12] cache rpc --- internal/rpc/msg/work_moments_notification.go | 6 +++--- internal/rpc/office/office.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/rpc/msg/work_moments_notification.go b/internal/rpc/msg/work_moments_notification.go index af333a354..b8eaff9a4 100644 --- a/internal/rpc/msg/work_moments_notification.go +++ b/internal/rpc/msg/work_moments_notification.go @@ -12,9 +12,9 @@ import ( func WorkMomentSendNotification(operationID, sendID, recvID string, notificationMsg *pbOffice.WorkMomentNotificationMsg) { log.NewInfo(operationID, utils.GetSelfFuncName(), sendID, recvID, notificationMsg) - //if sendID == recvID { - // return - //} + if sendID == recvID { + return + } WorkMomentNotification(operationID, sendID, recvID, notificationMsg) } diff --git a/internal/rpc/office/office.go b/internal/rpc/office/office.go index 19b21a8ec..e0397d572 100644 --- a/internal/rpc/office/office.go +++ b/internal/rpc/office/office.go @@ -305,7 +305,7 @@ func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.Crea UserName: createUser.Nickname, CreateTime: workMoment.CreateTime, } - msg.WorkMomentSendNotification(req.OperationID, atUser.UserID, atUser.UserID, workMomentNotificationMsg) + msg.WorkMomentSendNotification(req.OperationID, req.WorkMoment.UserID, atUser.UserID, workMomentNotificationMsg) } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil From 490f4f36f1584c1c95e8851300442d4f049c033e Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 14:43:55 +0800 Subject: [PATCH 06/12] cache rpc --- internal/rpc/msg/work_moments_notification.go | 9 +++------ internal/rpc/office/office.go | 8 ++++---- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/internal/rpc/msg/work_moments_notification.go b/internal/rpc/msg/work_moments_notification.go index b8eaff9a4..a8ed67c93 100644 --- a/internal/rpc/msg/work_moments_notification.go +++ b/internal/rpc/msg/work_moments_notification.go @@ -10,12 +10,9 @@ import ( "github.com/golang/protobuf/proto" ) -func WorkMomentSendNotification(operationID, sendID, recvID string, notificationMsg *pbOffice.WorkMomentNotificationMsg) { - log.NewInfo(operationID, utils.GetSelfFuncName(), sendID, recvID, notificationMsg) - if sendID == recvID { - return - } - WorkMomentNotification(operationID, sendID, recvID, notificationMsg) +func WorkMomentSendNotification(operationID, recvID string, notificationMsg *pbOffice.WorkMomentNotificationMsg) { + log.NewInfo(operationID, utils.GetSelfFuncName(), recvID, notificationMsg) + WorkMomentNotification(operationID, recvID, recvID, notificationMsg) } func WorkMomentNotification(operationID, sendID, recvID string, m proto.Message) { diff --git a/internal/rpc/office/office.go b/internal/rpc/office/office.go index e0397d572..869a03362 100644 --- a/internal/rpc/office/office.go +++ b/internal/rpc/office/office.go @@ -305,7 +305,7 @@ func (s *officeServer) CreateOneWorkMoment(_ context.Context, req *pbOffice.Crea UserName: createUser.Nickname, CreateTime: workMoment.CreateTime, } - msg.WorkMomentSendNotification(req.OperationID, req.WorkMoment.UserID, atUser.UserID, workMomentNotificationMsg) + msg.WorkMomentSendNotification(req.OperationID, atUser.UserID, workMomentNotificationMsg) } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil @@ -399,7 +399,7 @@ func (s *officeServer) LikeOneWorkMoment(_ context.Context, req *pbOffice.LikeOn } // send notification if like { - msg.WorkMomentSendNotification(req.OperationID, req.UserID, workMoment.UserID, workMomentNotificationMsg) + msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg) } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil @@ -450,9 +450,9 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com Content: comment.Content, CreateTime: comment.CreateTime, } - msg.WorkMomentSendNotification(req.OperationID, req.UserID, workMoment.UserID, workMomentNotificationMsg) + msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg) if req.ReplyUserID != "" { - msg.WorkMomentSendNotification(req.OperationID, req.UserID, req.ReplyUserID, workMomentNotificationMsg) + msg.WorkMomentSendNotification(req.OperationID, req.ReplyUserID, workMomentNotificationMsg) } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) return resp, nil From 338acfba759ae93d4221a2940cab00566ab58be7 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 14:57:15 +0800 Subject: [PATCH 07/12] cache rpc --- internal/rpc/office/office.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/rpc/office/office.go b/internal/rpc/office/office.go index 869a03362..674dcf773 100644 --- a/internal/rpc/office/office.go +++ b/internal/rpc/office/office.go @@ -398,7 +398,7 @@ func (s *officeServer) LikeOneWorkMoment(_ context.Context, req *pbOffice.LikeOn CreateTime: int32(time.Now().Unix()), } // send notification - if like { + if like && workMoment.UserID != req.UserID { msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg) } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) @@ -450,7 +450,9 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com Content: comment.Content, CreateTime: comment.CreateTime, } - msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg) + if req.UserID != workMoment.UserID { + msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg) + } if req.ReplyUserID != "" { msg.WorkMomentSendNotification(req.OperationID, req.ReplyUserID, workMomentNotificationMsg) } From 39822f323fd289d25d0fcb2a735361c12aa8d4ae Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 15:05:23 +0800 Subject: [PATCH 08/12] work moments --- internal/rpc/office/office.go | 2 +- internal/rpc/user/user.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/internal/rpc/office/office.go b/internal/rpc/office/office.go index 674dcf773..ab9da950a 100644 --- a/internal/rpc/office/office.go +++ b/internal/rpc/office/office.go @@ -453,7 +453,7 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com if req.UserID != workMoment.UserID { msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg) } - if req.ReplyUserID != "" { + if req.ReplyUserID != "" && req.ReplyUserID != req.UserID { msg.WorkMomentSendNotification(req.OperationID, req.ReplyUserID, workMomentNotificationMsg) } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 23423bcd4..f3e688588 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -389,6 +389,10 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, v.FriendUser.UserID) chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, v.FriendUser.UserID) } + + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName) + client := pbFriend.NewFriendClient(etcdConn) + chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, req.OpUserID) log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, req.OpUserID) return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil From 1a2aa876e326e1ae452793f35ebf06f437e1f7cb Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 15:06:43 +0800 Subject: [PATCH 09/12] work moments --- internal/rpc/user/user.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index f3e688588..7ed1059ed 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -390,8 +390,8 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, v.FriendUser.UserID) } - etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName) - client := pbFriend.NewFriendClient(etcdConn) + //etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImFriendName) + //client := pbFriend.NewFriendClient(etcdConn) chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, req.OpUserID) log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, req.OpUserID) From 37c40d7dda28d58fc3c523a1b3132a36a3f27863 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 15:52:03 +0800 Subject: [PATCH 10/12] work moments --- internal/rpc/office/office.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/rpc/office/office.go b/internal/rpc/office/office.go index ab9da950a..e0ef89e43 100644 --- a/internal/rpc/office/office.go +++ b/internal/rpc/office/office.go @@ -453,7 +453,7 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com if req.UserID != workMoment.UserID { msg.WorkMomentSendNotification(req.OperationID, workMoment.UserID, workMomentNotificationMsg) } - if req.ReplyUserID != "" && req.ReplyUserID != req.UserID { + if req.ReplyUserID != "" && req.ReplyUserID != workMoment.UserID && req.ReplyUserID != req.UserID { msg.WorkMomentSendNotification(req.OperationID, req.ReplyUserID, workMomentNotificationMsg) } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) From 17f6b8eb2ac13f627c2f19df56f99092a5e09d33 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 16:01:48 +0800 Subject: [PATCH 11/12] work moments --- internal/api/user/user.go | 199 ++++++++++++++++++++++---------------- pkg/common/db/model.go | 24 ++--- 2 files changed, 125 insertions(+), 98 deletions(-) diff --git a/internal/api/user/user.go b/internal/api/user/user.go index d6b733f03..437774972 100644 --- a/internal/api/user/user.go +++ b/internal/api/user/user.go @@ -8,7 +8,6 @@ import ( "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" "Open_IM/pkg/grpc-etcdv3/getcdv3" - cacheRpc "Open_IM/pkg/proto/cache" pbRelay "Open_IM/pkg/proto/relay" open_im_sdk "Open_IM/pkg/proto/sdk_ws" rpc "Open_IM/pkg/proto/user" @@ -19,6 +18,110 @@ import ( "strings" ) +//func GetUsersInfoFromCache(c *gin.Context) { +// params := api.GetUsersInfoReq{} +// if err := c.BindJSON(¶ms); err != nil { +// log.NewError("0", "BindJSON failed ", err.Error()) +// c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()}) +// return +// } +// getUserInfoReq := &rpc.GetUserInfoReq{} +// getUserInfoReq.OperationID = params.OperationID +// var ok bool +// ok, getUserInfoReq.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), getUserInfoReq.OperationID) +// if !ok { +// log.NewError(getUserInfoReq.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) +// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) +// return +// } +// log.NewInfo(params.OperationID, "GetUserInfo args ", getUserInfoReq.String()) +// reqCacheGetUserInfo := &cacheRpc.GetUserInfoReq{} +// utils.CopyStructFields(reqCacheGetUserInfo, ¶ms) +// var userInfoList []*open_im_sdk.UserInfo +// var publicUserInfoList []*open_im_sdk.PublicUserInfo +// etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName) +// cacheClient := cacheRpc.NewCacheClient(etcdConn) +// cacheResp, err := cacheClient.GetUserInfo(context.Background(), reqCacheGetUserInfo) +// if err != nil { +// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", err.Error()) +// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed: " + err.Error()}) +// return +// } +// if cacheResp.CommonResp.ErrCode != 0 { +// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp) +// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} +// resp.Data = []map[string]interface{}{} +// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) +// c.JSON(http.StatusOK, resp) +// return +// } +// log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "cacheResp:", cacheResp.String()) +// userInfoList = cacheResp.UserInfoList +// var needCacheUserIDList []string +// for _, userID := range reqCacheGetUserInfo.UserIDList { +// isGetUserInfoFromCache := false +// for _, cacheUser := range userInfoList { +// if cacheUser.UserID == userID { +// isGetUserInfoFromCache = true +// } +// } +// if !isGetUserInfoFromCache { +// needCacheUserIDList = append(needCacheUserIDList, userID) +// } +// } +// if len(needCacheUserIDList) == 0 { +// log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "get all userInfo from cache success") +// for _, v := range userInfoList { +// publicUserInfoList = append(publicUserInfoList, +// &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) +// } +// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} +// resp.Data = jsonData.JsonDataList(resp.UserInfoList) +// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) +// c.JSON(http.StatusOK, resp) +// return +// } +// +// log.NewDebug(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "need cache user list", needCacheUserIDList) +// getUserInfoReq.UserIDList = needCacheUserIDList +// etcdConn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) +// client := rpc.NewUserClient(etcdConn) +// rpcResp, err := client.GetUserInfo(context.Background(), getUserInfoReq) +// if err != nil { +// log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error(), getUserInfoReq.String()) +// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed" + err.Error()}) +// return +// } +// if rpcResp.CommonResp.ErrCode != 0 { +// log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp) +// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} +// resp.Data = []map[string]interface{}{} +// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) +// c.JSON(http.StatusOK, resp) +// return +// } +// userInfoList = append(userInfoList, rpcResp.UserInfoList...) +// cacheUpdateUserInfoReq := &cacheRpc.UpdateUserInfoReq{ +// UserInfoList: rpcResp.UserInfoList, +// OperationID: getUserInfoReq.OperationID, +// } +// _, err = cacheClient.UpdateUserInfo(context.Background(), cacheUpdateUserInfoReq) +// if err != nil { +// log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error()) +// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed:" + err.Error()}) +// return +// } +// userInfoList = rpcResp.UserInfoList +// for _, v := range userInfoList { +// publicUserInfoList = append(publicUserInfoList, +// &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) +// } +// resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} +// resp.Data = jsonData.JsonDataList(resp.UserInfoList) +// log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) +// c.JSON(http.StatusOK, resp) +//} + func GetUsersInfoFromCache(c *gin.Context) { params := api.GetUsersInfoReq{} if err := c.BindJSON(¶ms); err != nil { @@ -26,100 +129,34 @@ func GetUsersInfoFromCache(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": http.StatusBadRequest, "errMsg": err.Error()}) return } - getUserInfoReq := &rpc.GetUserInfoReq{} - getUserInfoReq.OperationID = params.OperationID + req := &rpc.GetUserInfoReq{} + utils.CopyStructFields(req, ¶ms) var ok bool - ok, getUserInfoReq.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), getUserInfoReq.OperationID) + ok, req.OpUserID = token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID) if !ok { - log.NewError(getUserInfoReq.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) + log.NewError(req.OperationID, "GetUserIDFromToken false ", c.Request.Header.Get("token")) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "GetUserIDFromToken failed"}) return } - log.NewInfo(params.OperationID, "GetUserInfo args ", getUserInfoReq.String()) - reqCacheGetUserInfo := &cacheRpc.GetUserInfoReq{} - utils.CopyStructFields(reqCacheGetUserInfo, ¶ms) - var userInfoList []*open_im_sdk.UserInfo - var publicUserInfoList []*open_im_sdk.PublicUserInfo - etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName) - cacheClient := cacheRpc.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.GetUserInfo(context.Background(), reqCacheGetUserInfo) - if err != nil { - log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", err.Error()) - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed: " + err.Error()}) - return - } - if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp) - resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} - resp.Data = []map[string]interface{}{} - log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) - c.JSON(http.StatusOK, resp) - return - } - log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "cacheResp:", cacheResp.String()) - userInfoList = cacheResp.UserInfoList - var needCacheUserIDList []string - for _, userID := range reqCacheGetUserInfo.UserIDList { - isGetUserInfoFromCache := false - for _, cacheUser := range userInfoList { - if cacheUser.UserID == userID { - isGetUserInfoFromCache = true - } - } - if !isGetUserInfoFromCache { - needCacheUserIDList = append(needCacheUserIDList, userID) - } - } - if len(needCacheUserIDList) == 0 { - log.NewInfo(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "get all userInfo from cache success") - for _, v := range userInfoList { - publicUserInfoList = append(publicUserInfoList, - &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) - } - resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} - resp.Data = jsonData.JsonDataList(resp.UserInfoList) - log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) - c.JSON(http.StatusOK, resp) - return - } + log.NewInfo(params.OperationID, "GetUserInfo args ", req.String()) - log.NewDebug(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "need cache user list", needCacheUserIDList) - getUserInfoReq.UserIDList = needCacheUserIDList - etcdConn = getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImUserName) client := rpc.NewUserClient(etcdConn) - rpcResp, err := client.GetUserInfo(context.Background(), getUserInfoReq) + RpcResp, err := client.GetUserInfo(context.Background(), req) if err != nil { - log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error(), getUserInfoReq.String()) - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed" + err.Error()}) + log.NewError(req.OperationID, "GetUserInfo failed ", err.Error(), req.String()) + c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed"}) return } - if rpcResp.CommonResp.ErrCode != 0 { - log.NewError(getUserInfoReq.OperationID, utils.GetSelfFuncName(), "GetUserInfo failed", cacheResp.CommonResp) - resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}} - resp.Data = []map[string]interface{}{} - log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) - c.JSON(http.StatusOK, resp) - return - } - userInfoList = append(userInfoList, rpcResp.UserInfoList...) - cacheUpdateUserInfoReq := &cacheRpc.UpdateUserInfoReq{ - UserInfoList: rpcResp.UserInfoList, - OperationID: getUserInfoReq.OperationID, - } - _, err = cacheClient.UpdateUserInfo(context.Background(), cacheUpdateUserInfoReq) - if err != nil { - log.NewError(getUserInfoReq.OperationID, "GetUserInfo failed ", err.Error()) - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call rpc server failed:" + err.Error()}) - return - } - userInfoList = rpcResp.UserInfoList - for _, v := range userInfoList { + var publicUserInfoList []*open_im_sdk.PublicUserInfo + for _, v := range RpcResp.UserInfoList { publicUserInfoList = append(publicUserInfoList, &open_im_sdk.PublicUserInfo{UserID: v.UserID, Nickname: v.Nickname, FaceURL: v.FaceURL, Gender: v.Gender, Ex: v.Ex}) } - resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: rpcResp.CommonResp.ErrCode, ErrMsg: rpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} + + resp := api.GetUsersInfoResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserInfoList: publicUserInfoList} resp.Data = jsonData.JsonDataList(resp.UserInfoList) - log.NewInfo(getUserInfoReq.OperationID, "GetUserInfo api return ", resp) + log.NewInfo(req.OperationID, "GetUserInfo api return ", resp) c.JSON(http.StatusOK, resp) } diff --git a/pkg/common/db/model.go b/pkg/common/db/model.go index 2fe0ed367..e50d7dc11 100644 --- a/pkg/common/db/model.go +++ b/pkg/common/db/model.go @@ -71,24 +71,14 @@ func init() { opts := options.CreateIndexes().SetMaxTime(10 * time.Second) dataBase := mongoClient.Database(config.Config.Mongo.DBDatabase) - cCommentMsgModels := []mongo.IndexModel{ - { - Keys: bson.A{bson.D{{"create_time", -1}, {"user_id", -1}}}, - }, - } - result, err := dataBase.Collection(cCommentMsg).Indexes().CreateMany(context.Background(), cCommentMsgModels, opts) - if err != nil { - fmt.Println("mongodb create cCommentMsgModels failed", result, err.Error()) - } - cSendLogModels := []mongo.IndexModel{ { - Keys: bson.M{"user_id": -1, "send_time": -1}, + Keys: bson.M{"user_id": -1}, }, } - result, err = dataBase.Collection(cSendLog).Indexes().CreateMany(context.Background(), cSendLogModels, opts) + result, err := dataBase.Collection(cSendLog).Indexes().CreateMany(context.Background(), cSendLogModels, opts) if err != nil { - fmt.Println("mongodb create cSendLogModels failed", result, err.Error()) + //fmt.Println("mongodb create cSendLogModels failed", result, err.Error()) } cChatModels := []mongo.IndexModel{ @@ -106,12 +96,12 @@ func init() { Keys: bson.M{"work_moment_id": -1}, }, { - Keys: bson.M{"user_id": -1, "create_time": -1}, + Keys: bson.M{"user_id": -1}, }, } result, err = dataBase.Collection(cWorkMoment).Indexes().CreateMany(context.Background(), cWorkMomentModels, opts) if err != nil { - fmt.Println("mongodb create cWorkMomentModels failed", result, err.Error()) + //fmt.Println("mongodb create cWorkMomentModels failed", result, err.Error()) } cTagModels := []mongo.IndexModel{ @@ -119,12 +109,12 @@ func init() { Keys: bson.M{"tag_id": -1}, }, { - Keys: bson.M{"user_id": -1, "tag_id": -1}, + Keys: bson.M{"user_id": -1}, }, } result, err = dataBase.Collection(cTag).Indexes().CreateMany(context.Background(), cTagModels, opts) if err != nil { - fmt.Println("mongodb create cTagModels failed", result, err.Error()) + //fmt.Println("mongodb create cTagModels failed", result, err.Error()) } DB.mongoClient = mongoClient From 7b0eb4e79de119c8cafa59ede8d3ef8ce7de9ed8 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Tue, 26 Apr 2022 16:24:43 +0800 Subject: [PATCH 12/12] work moments --- internal/rpc/office/office.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/rpc/office/office.go b/internal/rpc/office/office.go index e0ef89e43..17c8dc598 100644 --- a/internal/rpc/office/office.go +++ b/internal/rpc/office/office.go @@ -441,9 +441,9 @@ func (s *officeServer) CommentOneWorkMoment(_ context.Context, req *pbOffice.Com NotificationMsgType: constant.WorkMomentCommentNotification, WorkMomentID: workMoment.WorkMomentID, WorkMomentContent: workMoment.Content, - UserID: workMoment.UserID, - FaceURL: workMoment.FaceURL, - UserName: workMoment.UserName, + UserID: commentUser.UserID, + FaceURL: commentUser.FaceURL, + UserName: commentUser.Nickname, ReplyUserID: comment.ReplyUserID, ReplyUserName: comment.ReplyUserName, ContentID: comment.ContentID,