diff --git a/test/mongo/cmd/main.go b/cmdutils/mongo/cmd/main.go similarity index 100% rename from test/mongo/cmd/main.go rename to cmdutils/mongo/cmd/main.go diff --git a/test/mongo/mongo_utils.go b/cmdutils/mongo/mongo_utils.go similarity index 100% rename from test/mongo/mongo_utils.go rename to cmdutils/mongo/mongo_utils.go diff --git a/internal/api/auth/auth.go b/internal/api/auth/auth.go index a2b0248f0..132f19e6a 100644 --- a/internal/api/auth/auth.go +++ b/internal/api/auth/auth.go @@ -1,7 +1,7 @@ package apiAuth import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" diff --git a/internal/api/client_init/init_config.go b/internal/api/client_init/init_config.go index 2138603c4..927ffc8f9 100644 --- a/internal/api/client_init/init_config.go +++ b/internal/api/client_init/init_config.go @@ -1,7 +1,7 @@ package clientInit import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" diff --git a/internal/api/conversation/conversation.go b/internal/api/conversation/conversation.go index a063a7eb0..8cdfd0868 100644 --- a/internal/api/conversation/conversation.go +++ b/internal/api/conversation/conversation.go @@ -1,7 +1,7 @@ package conversation import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/log" "Open_IM/pkg/getcdv3" diff --git a/internal/api/friend/friend.go b/internal/api/friend/friend.go index 7c4ca05d6..499fdf52f 100644 --- a/internal/api/friend/friend.go +++ b/internal/api/friend/friend.go @@ -2,7 +2,7 @@ package friend //import ( // jsonData "Open_IM/internal/utils" -// api "Open_IM/pkg/base_info" +// api "Open_IM/pkg/api_struct" // "Open_IM/pkg/common/config" // "Open_IM/pkg/common/log" // "Open_IM/pkg/common/token_verify" diff --git a/internal/api/friend/friend1.go b/internal/api/friend/friend1.go index f4fdf9bb1..a3469245c 100644 --- a/internal/api/friend/friend1.go +++ b/internal/api/friend/friend1.go @@ -2,7 +2,7 @@ package friend import ( common "Open_IM/internal/api_to_rpc" - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" rpc "Open_IM/pkg/proto/friend" "github.com/gin-gonic/gin" diff --git a/internal/api/group/group.go b/internal/api/group/group.go index f217923c7..7e4dc357c 100644 --- a/internal/api/group/group.go +++ b/internal/api/group/group.go @@ -2,7 +2,7 @@ package group import ( common "Open_IM/internal/api_to_rpc" - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" diff --git a/internal/api/group/super_group.go b/internal/api/group/super_group.go index dc38bc94e..ab1dceb2f 100644 --- a/internal/api/group/super_group.go +++ b/internal/api/group/super_group.go @@ -2,7 +2,7 @@ package group import ( jsonData "Open_IM/internal/utils" - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" diff --git a/internal/api/manage/management_chat.go b/internal/api/manage/management_chat.go index f89280ea4..ff8cca04f 100644 --- a/internal/api/manage/management_chat.go +++ b/internal/api/manage/management_chat.go @@ -7,7 +7,7 @@ package manage import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db/mysql_model/im_mysql_model" diff --git a/internal/api/manage/management_user.go b/internal/api/manage/management_user.go index e307d1beb..c4772ef67 100644 --- a/internal/api/manage/management_user.go +++ b/internal/api/manage/management_user.go @@ -7,7 +7,7 @@ package manage import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" diff --git a/internal/api/msg/del_msg.go b/internal/api/msg/del_msg.go index 7bd7bfaef..d5d2b71f6 100644 --- a/internal/api/msg/del_msg.go +++ b/internal/api/msg/del_msg.go @@ -1,7 +1,7 @@ package msg import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" diff --git a/internal/api/msg/extend_msg.go b/internal/api/msg/extend_msg.go index d217073bb..d74017811 100644 --- a/internal/api/msg/extend_msg.go +++ b/internal/api/msg/extend_msg.go @@ -1,7 +1,7 @@ package msg import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" diff --git a/internal/api/office/tag.go b/internal/api/office/tag.go index 7c4f5a606..68d787ad8 100644 --- a/internal/api/office/tag.go +++ b/internal/api/office/tag.go @@ -1,7 +1,7 @@ package office import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" diff --git a/internal/api/office/work_moments.go b/internal/api/office/work_moments.go index 8a8c52920..f84755277 100644 --- a/internal/api/office/work_moments.go +++ b/internal/api/office/work_moments.go @@ -1,7 +1,7 @@ package office import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" diff --git a/internal/api/third/ali_oss_credential.go b/internal/api/third/ali_oss_credential.go index 0602143e8..14ce0f9fa 100644 --- a/internal/api/third/ali_oss_credential.go +++ b/internal/api/third/ali_oss_credential.go @@ -1,7 +1,7 @@ package apiThird import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" diff --git a/internal/api/third/aws_storage_credential.go b/internal/api/third/aws_storage_credential.go index 4b3b7d08a..e68073d01 100644 --- a/internal/api/third/aws_storage_credential.go +++ b/internal/api/third/aws_storage_credential.go @@ -1,7 +1,7 @@ package apiThird import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" diff --git a/internal/api/third/fcm_update_token.go b/internal/api/third/fcm_update_token.go index 000deaabb..22b93a629 100644 --- a/internal/api/third/fcm_update_token.go +++ b/internal/api/third/fcm_update_token.go @@ -1,7 +1,7 @@ package apiThird import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/db" "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" diff --git a/internal/api/third/minio_storage_credential.go b/internal/api/third/minio_storage_credential.go index 753d3b182..f500ffb8a 100644 --- a/internal/api/third/minio_storage_credential.go +++ b/internal/api/third/minio_storage_credential.go @@ -1,7 +1,7 @@ package apiThird import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" diff --git a/internal/api/third/rtc.go b/internal/api/third/rtc.go index 576e32892..2e7d1044d 100644 --- a/internal/api/third/rtc.go +++ b/internal/api/third/rtc.go @@ -1,7 +1,7 @@ package apiThird import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/db" "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" diff --git a/internal/api/third/set_app_badge.go b/internal/api/third/set_app_badge.go index e8269ba73..37dcad72a 100644 --- a/internal/api/third/set_app_badge.go +++ b/internal/api/third/set_app_badge.go @@ -1,7 +1,7 @@ package apiThird import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/db" "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" diff --git a/internal/api/third/tencent_cloud_storage_credential.go b/internal/api/third/tencent_cloud_storage_credential.go index 4f641f1aa..4cfbe485f 100644 --- a/internal/api/third/tencent_cloud_storage_credential.go +++ b/internal/api/third/tencent_cloud_storage_credential.go @@ -1,7 +1,7 @@ package apiThird import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" diff --git a/internal/api/user/user.go b/internal/api/user/user.go index f289a4f49..31bba9909 100644 --- a/internal/api/user/user.go +++ b/internal/api/user/user.go @@ -2,7 +2,7 @@ package user import ( jsonData "Open_IM/internal/utils" - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" diff --git a/internal/api_to_rpc/api.go b/internal/api_to_rpc/api.go index 43118ca16..b3d65a131 100644 --- a/internal/api_to_rpc/api.go +++ b/internal/api_to_rpc/api.go @@ -1,6 +1,7 @@ package common import ( + "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" "Open_IM/pkg/common/tracelog" "Open_IM/pkg/getcdv3" @@ -8,7 +9,10 @@ import ( "context" "fmt" "github.com/gin-gonic/gin" + "google.golang.org/grpc/status" + "net/http" "reflect" + "strings" ) func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcClientFunc interface{}, rpcFuncName string) { @@ -16,16 +20,16 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcCl rpcName = utils2.GetFuncName(1) } logFuncName := fmt.Sprintf("[ApiToRpc: %s]%s", utils2.GetFuncName(1), rpcFuncName) - ctx := tracelog.NewCtx1(c, rpcFuncName) + ctx := tracelog.NewCtx(c, rpcFuncName) defer log.ShowLog(ctx) if err := c.BindJSON(apiReq); err != nil { - tracelog.WriteErrorResponse(ctx, "BindJSON", err) + WriteErrorResponse(ctx, "BindJSON", err) return } tracelog.SetCtxInfo(ctx, logFuncName, nil, "apiReq", apiReq) etcdConn, err := getcdv3.GetConn(ctx, rpcName) if err != nil { - tracelog.WriteErrorResponse(ctx, "GetConn", err) + WriteErrorResponse(ctx, "GetConn", err) return } rpcClient := reflect.ValueOf(rpcClientFunc).Call([]reflect.Value{ @@ -40,7 +44,7 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcCl }) // respArr => (apiResp, error) if !respArr[1].IsNil() { // rpcClient err != nil err := respArr[1].Interface().(error) - tracelog.WriteErrorResponse(ctx, rpcFuncName, err, "callRpcResp", "error") + WriteErrorResponse(ctx, rpcFuncName, err, "callRpcResp", "error") return } rpcResp := respArr[0].Elem() @@ -48,7 +52,7 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcCl if apiResp != nil { CopyAny(rpcResp.Interface(), apiResp) } - tracelog.SetSuccess(ctx, rpcFuncName, apiResp) + SetSuccess(ctx, rpcFuncName, apiResp) } func rpcString(v interface{}) string { @@ -57,3 +61,43 @@ func rpcString(v interface{}) string { } return fmt.Sprintf("%+v", v) } + +type baseResp struct { + ErrCode int32 `json:"errCode"` + ErrMsg string `json:"errMsg"` + ErrDtl string `json:"errDtl"` + Data interface{} `json:"data"` +} + +func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) { + tracelog.SetCtxInfo(ctx, funcName, err, args) + e := tracelog.Unwrap(err) + switch t := e.(type) { + case *constant.ErrInfo: + ctx.Value(tracelog.TraceLogKey).(*tracelog.ApiInfo).GinCtx.JSON(http.StatusOK, baseResp{ErrCode: t.ErrCode, ErrMsg: t.ErrMsg, ErrDtl: t.DetailErrMsg}) + //ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": t.ErrCode, "errMsg": t.ErrMsg, "errDtl": t.DetailErrMsg}) + return + default: + s, ok := status.FromError(e) + if !ok { + ctx.Value(tracelog.TraceLogKey).(*tracelog.ApiInfo).GinCtx.JSON(http.StatusOK, &baseResp{ErrCode: constant.ErrDefaultOther.ErrCode, ErrMsg: err.Error(), ErrDtl: fmt.Sprintf("%+v", err)}) + //ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": constant.ErrDefaultOther.ErrCode, "errMsg": err.Error(), "errDtl": fmt.Sprintf("%+v", err)}) + return + } + var details []string + if err != e { + details = append(details, fmt.Sprintf("%+v", err)) + } + for _, s := range s.Details() { + details = append(details, fmt.Sprintf("%+v", s)) + } + ctx.Value(tracelog.TraceLogKey).(*tracelog.ApiInfo).GinCtx.JSON(http.StatusOK, &baseResp{ErrCode: int32(s.Code()), ErrMsg: s.Message(), ErrDtl: strings.Join(details, "\n")}) + //ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": s.Code(), "errMsg": s.Message(), "errDtl": strings.Join(details, "\n")}) + return + } +} + +func SetSuccess(ctx context.Context, funcName string, data interface{}) { + tracelog.SetCtxInfo(ctx, funcName, nil, "data", data) + ctx.Value(tracelog.TraceLogKey).(*tracelog.ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "errDtl": "", "data": data}) +} diff --git a/internal/cms_api/admin/admin.go b/internal/cms_api/admin/admin.go index 754c77b76..8799a7d8e 100644 --- a/internal/cms_api/admin/admin.go +++ b/internal/cms_api/admin/admin.go @@ -126,95 +126,3 @@ func AdminLogin(c *gin.Context) { resp.Token = respPb.Token c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp}) } - -func AddUserRegisterAddFriendIDList(c *gin.Context) { - var ( - req apiStruct.AddUserRegisterAddFriendIDListRequest - // resp apiStruct.AddUserRegisterAddFriendIDListResponse - ) - if err := c.BindJSON(&req); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error()) - c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) - return - } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req:", req) - etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, req.OperationID) - if etcdConn == nil { - errMsg := req.OperationID + "getcdv3.GetConn == nil" - log.NewError(req.OperationID, errMsg) - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) - return - } - client := pbAdmin.NewAdminCMSClient(etcdConn) - respPb, err := client.AddUserRegisterAddFriendIDList(context.Background(), &pbAdmin.AddUserRegisterAddFriendIDListReq{OperationID: req.OperationID, UserIDList: req.UserIDList}) - if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error()) - c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()}) - return - } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp:", respPb.String()) - c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg}) -} - -func ReduceUserRegisterAddFriendIDList(c *gin.Context) { - var ( - req apiStruct.ReduceUserRegisterAddFriendIDListRequest - // resp apiStruct.ReduceUserRegisterAddFriendIDListResponse - ) - if err := c.BindJSON(&req); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error()) - c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) - return - } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req) - etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, req.OperationID) - if etcdConn == nil { - errMsg := req.OperationID + "getcdv3.GetConn == nil" - log.NewError(req.OperationID, errMsg) - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) - return - } - client := pbAdmin.NewAdminCMSClient(etcdConn) - respPb, err := client.ReduceUserRegisterAddFriendIDList(context.Background(), &pbAdmin.ReduceUserRegisterAddFriendIDListReq{OperationID: req.OperationID, UserIDList: req.UserIDList, Operation: req.Operation}) - if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error()) - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()}) - return - } - c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg}) -} - -func GetUserRegisterAddFriendIDList(c *gin.Context) { - var ( - req apiStruct.GetUserRegisterAddFriendIDListRequest - resp apiStruct.GetUserRegisterAddFriendIDListResponse - ) - if err := c.BindJSON(&req); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error()) - c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()}) - return - } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), req) - etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAdminCMSName, req.OperationID) - if etcdConn == nil { - errMsg := req.OperationID + "getcdv3.GetConn == nil" - log.NewError(req.OperationID, errMsg) - c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg}) - return - } - client := pbAdmin.NewAdminCMSClient(etcdConn) - respPb, err := client.GetUserRegisterAddFriendIDList(context.Background(), &pbAdmin.GetUserRegisterAddFriendIDListReq{OperationID: req.OperationID, Pagination: &pbCommon.RequestPagination{ - PageNumber: int32(req.PageNumber), - ShowNumber: int32(req.ShowNumber), - }}) - if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "rpc failed", err.Error()) - c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": err.Error()}) - return - } - resp.Users = respPb.UserInfoList - resp.ShowNumber = int(respPb.Pagination.ShowNumber) - resp.CurrentPage = int(respPb.Pagination.CurrentPage) - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), resp) - c.JSON(http.StatusOK, gin.H{"errCode": respPb.CommonResp.ErrCode, "errMsg": respPb.CommonResp.ErrMsg, "data": resp}) -} diff --git a/internal/cms_api/friend/friend.go b/internal/cms_api/friend/friend.go index ef5240079..e944dcd9c 100644 --- a/internal/cms_api/friend/friend.go +++ b/internal/cms_api/friend/friend.go @@ -17,8 +17,8 @@ import ( func GetUserFriends(c *gin.Context) { var ( - req cms_api_struct.GetFriendsReq - resp cms_api_struct.GetFriendsResp + req cms_struct.GetFriendsReq + resp cms_struct.GetFriendsResp reqPb pbAdmin.GetUserFriendsReq ) if err := c.BindJSON(&req); err != nil { @@ -49,7 +49,7 @@ func GetUserFriends(c *gin.Context) { return } for _, v := range respPb.FriendInfoList { - friend := &cms_api_struct.FriendInfo{} + friend := &cms_struct.FriendInfo{} utils.CopyStructFields(friend, v) friend.Nickname = v.FriendUser.Nickname friend.UserID = v.FriendUser.UserID diff --git a/internal/cms_api/group/group.go b/internal/cms_api/group/group.go index b18289b65..5f595ef5b 100644 --- a/internal/cms_api/group/group.go +++ b/internal/cms_api/group/group.go @@ -18,8 +18,8 @@ import ( func GetGroups(c *gin.Context) { var ( - req cms_api_struct.GetGroupsRequest - resp cms_api_struct.GetGroupsResponse + req cms_struct.GetGroupsRequest + resp cms_struct.GetGroupsResponse reqPb pbGroup.GetGroupsReq ) if err := c.BindJSON(&req); err != nil { @@ -48,7 +48,7 @@ func GetGroups(c *gin.Context) { return } for _, v := range respPb.CMSGroups { - groupResp := cms_api_struct.GroupResponse{} + groupResp := cms_struct.GroupResponse{} utils.CopyStructFields(&groupResp, v.GroupInfo) groupResp.GroupOwnerName = v.GroupOwnerUserName groupResp.GroupOwnerID = v.GroupOwnerUserID @@ -63,9 +63,9 @@ func GetGroups(c *gin.Context) { func GetGroupMembers(c *gin.Context) { var ( - req cms_api_struct.GetGroupMembersRequest + req cms_struct.GetGroupMembersRequest reqPb pbGroup.GetGroupMembersCMSReq - resp cms_api_struct.GetGroupMembersResponse + resp cms_struct.GetGroupMembersResponse ) if err := c.BindJSON(&req); err != nil { log.NewError(reqPb.OperationID, utils.GetSelfFuncName(), "BindJSON failed ", err.Error()) @@ -94,13 +94,13 @@ func GetGroupMembers(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()}) return } - resp.ResponsePagination = cms_api_struct.ResponsePagination{ + resp.ResponsePagination = cms_struct.ResponsePagination{ CurrentPage: int(respPb.Pagination.CurrentPage), ShowNumber: int(respPb.Pagination.ShowNumber), } resp.MemberNums = int(respPb.MemberNums) for _, groupMember := range respPb.Members { - memberResp := cms_api_struct.GroupMemberResponse{} + memberResp := cms_struct.GroupMemberResponse{} utils.CopyStructFields(&memberResp, groupMember) resp.GroupMembers = append(resp.GroupMembers, memberResp) } diff --git a/internal/cms_api/message_cms/message.go b/internal/cms_api/message_cms/message.go index 6b194a2f4..889c391b9 100644 --- a/internal/cms_api/message_cms/message.go +++ b/internal/cms_api/message_cms/message.go @@ -17,8 +17,8 @@ import ( func GetChatLogs(c *gin.Context) { var ( - req cms_api_struct.GetChatLogsReq - resp cms_api_struct.GetChatLogsResp + req cms_struct.GetChatLogsReq + resp cms_struct.GetChatLogsResp reqPb pbAdminCMS.GetChatLogsReq ) if err := c.Bind(&req); err != nil { @@ -47,7 +47,7 @@ func GetChatLogs(c *gin.Context) { return } for _, v := range respPb.ChatLogs { - chatLog := cms_api_struct.ChatLog{} + chatLog := cms_struct.ChatLog{} utils.CopyStructFields(&chatLog, v) resp.ChatLogs = append(resp.ChatLogs, &chatLog) } diff --git a/internal/cms_api/prome.go b/internal/cms_api/prome.go deleted file mode 100644 index dfe96d626..000000000 --- a/internal/cms_api/prome.go +++ /dev/null @@ -1,14 +0,0 @@ -package cms_api - -import ( - "github.com/gin-gonic/gin" - "github.com/prometheus/client_golang/prometheus/promhttp" -) - -func prometheusHandler() gin.HandlerFunc { - h := promhttp.Handler() - - return func(c *gin.Context) { - h.ServeHTTP(c.Writer, c.Request) - } -} diff --git a/internal/cms_api/router.go b/internal/cms_api/router.go index 98aa8fce2..7fbb8db1e 100644 --- a/internal/cms_api/router.go +++ b/internal/cms_api/router.go @@ -8,7 +8,6 @@ import ( "Open_IM/internal/cms_api/middleware" "Open_IM/internal/cms_api/statistics" "Open_IM/internal/cms_api/user" - "Open_IM/internal/demo/register" "Open_IM/pkg/common/config" promePkg "Open_IM/pkg/common/prometheus" @@ -30,22 +29,6 @@ func NewGinRouter() *gin.Engine { adminRouterGroup.POST("/login", admin.AdminLogin) adminRouterGroup.Use(middleware.JWTAuth()) adminRouterGroup.POST("/get_user_token", admin.GetUserToken) - - adminRouterGroup.POST("/add_user_register_add_friend_id", admin.AddUserRegisterAddFriendIDList) - adminRouterGroup.POST("/reduce_user_register_reduce_friend_id", admin.ReduceUserRegisterAddFriendIDList) - adminRouterGroup.POST("/get_user_register_reduce_friend_id_list", admin.GetUserRegisterAddFriendIDList) - - adminRouterGroup.POST("/generate_invitation_code", register.GenerateInvitationCode) - adminRouterGroup.POST("/query_invitation_code", register.QueryInvitationCode) - adminRouterGroup.POST("/get_invitation_codes", register.GetInvitationCodes) - - adminRouterGroup.POST("/query_user_ip_limit_login", register.QueryUserIDLimitLogin) - adminRouterGroup.POST("/add_user_ip_limit_login", register.AddUserIPLimitLogin) - adminRouterGroup.POST("/remove_user_ip_limit_login", register.RemoveUserIPLimitLogin) - - adminRouterGroup.POST("/query_ip_register", register.QueryIPRegister) - adminRouterGroup.POST("/add_ip_limit", register.AddIPLimit) - adminRouterGroup.POST("/remove_ip_Limit", register.RemoveIPLimit) } r2 := router.Group("") r2.Use(middleware.JWTAuth()) diff --git a/internal/cms_api/statistics/statistics.go b/internal/cms_api/statistics/statistics.go index 2f96d7ddd..04f229be0 100644 --- a/internal/cms_api/statistics/statistics.go +++ b/internal/cms_api/statistics/statistics.go @@ -17,8 +17,8 @@ import ( func GetMessagesStatistics(c *gin.Context) { var ( - req cms_api_struct.GetMessageStatisticsRequest - resp cms_api_struct.GetMessageStatisticsResponse + req cms_struct.GetMessageStatisticsRequest + resp cms_struct.GetMessageStatisticsResponse reqPb admin.GetMessageStatisticsReq ) reqPb.StatisticsReq = &admin.StatisticsReq{} @@ -73,8 +73,8 @@ func GetMessagesStatistics(c *gin.Context) { func GetUserStatistics(c *gin.Context) { var ( - req cms_api_struct.GetUserStatisticsRequest - resp cms_api_struct.GetUserStatisticsResponse + req cms_struct.GetUserStatisticsRequest + resp cms_struct.GetUserStatisticsResponse reqPb admin.GetUserStatisticsReq ) reqPb.StatisticsReq = &admin.StatisticsReq{} @@ -138,8 +138,8 @@ func GetUserStatistics(c *gin.Context) { func GetGroupStatistics(c *gin.Context) { var ( - req cms_api_struct.GetGroupStatisticsRequest - resp cms_api_struct.GetGroupStatisticsResponse + req cms_struct.GetGroupStatisticsRequest + resp cms_struct.GetGroupStatisticsResponse reqPb admin.GetGroupStatisticsReq ) reqPb.StatisticsReq = &admin.StatisticsReq{} @@ -197,8 +197,8 @@ func GetGroupStatistics(c *gin.Context) { func GetActiveUser(c *gin.Context) { var ( - req cms_api_struct.GetActiveUserRequest - resp cms_api_struct.GetActiveUserResponse + req cms_struct.GetActiveUserRequest + resp cms_struct.GetActiveUserResponse reqPb admin.GetActiveUserReq ) reqPb.StatisticsReq = &admin.StatisticsReq{} @@ -233,8 +233,8 @@ func GetActiveUser(c *gin.Context) { func GetActiveGroup(c *gin.Context) { var ( - req cms_api_struct.GetActiveGroupRequest - resp cms_api_struct.GetActiveGroupResponse + req cms_struct.GetActiveGroupRequest + resp cms_struct.GetActiveGroupResponse reqPb admin.GetActiveGroupReq ) reqPb.StatisticsReq = &admin.StatisticsReq{} diff --git a/internal/cms_api/user/user.go b/internal/cms_api/user/user.go index e6c374aa2..7f103ba57 100644 --- a/internal/cms_api/user/user.go +++ b/internal/cms_api/user/user.go @@ -18,7 +18,7 @@ import ( func AddUser(c *gin.Context) { var ( - req cms_api_struct.AddUserRequest + req cms_struct.AddUserRequest reqPb pb.AddUserReq ) if err := c.BindJSON(&req); err != nil { @@ -48,7 +48,7 @@ func AddUser(c *gin.Context) { func BlockUser(c *gin.Context) { var ( - req cms_api_struct.BlockUserRequest + req cms_struct.BlockUserRequest reqPb pb.BlockUserReq ) if err := c.BindJSON(&req); err != nil { @@ -78,8 +78,8 @@ func BlockUser(c *gin.Context) { func UnblockUser(c *gin.Context) { var ( - req cms_api_struct.UnblockUserRequest - resp cms_api_struct.UnBlockUserResponse + req cms_struct.UnblockUserRequest + resp cms_struct.UnBlockUserResponse reqPb pb.UnBlockUserReq ) if err := c.BindJSON(&req); err != nil { @@ -110,8 +110,8 @@ func UnblockUser(c *gin.Context) { func GetBlockUsers(c *gin.Context) { var ( - req cms_api_struct.GetBlockUsersRequest - resp cms_api_struct.GetBlockUsersResponse + req cms_struct.GetBlockUsersRequest + resp cms_struct.GetBlockUsersResponse reqPb pb.GetBlockUsersReq respPb *pb.GetBlockUsersResp ) @@ -140,8 +140,8 @@ func GetBlockUsers(c *gin.Context) { return } for _, v := range respPb.BlockUsers { - resp.BlockUsers = append(resp.BlockUsers, cms_api_struct.BlockUser{ - UserResponse: cms_api_struct.UserResponse{ + resp.BlockUsers = append(resp.BlockUsers, cms_struct.BlockUser{ + UserResponse: cms_struct.UserResponse{ UserID: v.UserInfo.UserID, FaceURL: v.UserInfo.FaceURL, Nickname: v.UserInfo.Nickname, @@ -162,8 +162,8 @@ func GetBlockUsers(c *gin.Context) { func GetUserIDByEmailAndPhoneNumber(c *gin.Context) { var ( - req cms_api_struct.GetUserIDByEmailAndPhoneNumberRequest - resp cms_api_struct.GetUserIDByEmailAndPhoneNumberResponse + req cms_struct.GetUserIDByEmailAndPhoneNumberRequest + resp cms_struct.GetUserIDByEmailAndPhoneNumberResponse reqPb pbAdminCms.GetUserIDByEmailAndPhoneNumberReq respPb *pbAdminCms.GetUserIDByEmailAndPhoneNumberResp ) diff --git a/internal/cron_task/cron_task.go b/internal/cron_task/cron_task.go index 0b23e9125..c261fc48b 100644 --- a/internal/cron_task/cron_task.go +++ b/internal/cron_task/cron_task.go @@ -44,13 +44,16 @@ func StartCronTask(userID, workingGroupID string) { } } +type CronTask struct { +} + func getCronTaskOperationID() string { return cronTaskOperationID + utils.OperationIDGenerator() } func ClearAll() { operationID := getCronTaskOperationID() - log.NewInfo(operationID, "====================== start del cron task ======================") + log.NewInfo(operationID, "========================= start del cron task =========================") var err error userIDList, err := im_mysql_model.SelectAllUserID() if err == nil { @@ -67,7 +70,7 @@ func ClearAll() { log.NewError(operationID, utils.GetSelfFuncName(), err.Error()) } - log.NewInfo(operationID, "====================== start del cron finished ======================") + log.NewInfo(operationID, "========================= start del cron finished =========================") } func StartClearMsg(operationID string, userIDList []string) { diff --git a/internal/demo/register/login.go b/internal/demo/register/login.go index e48294055..7d05086eb 100644 --- a/internal/demo/register/login.go +++ b/internal/demo/register/login.go @@ -1,7 +1,7 @@ package register import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db/mysql_model/im_mysql_model" diff --git a/internal/demo/register/set_password.go b/internal/demo/register/set_password.go index ce2ca417e..e2f141080 100644 --- a/internal/demo/register/set_password.go +++ b/internal/demo/register/set_password.go @@ -1,7 +1,7 @@ package register import ( - api "Open_IM/pkg/base_info" + api "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" diff --git a/internal/msg_transfer/logic/modify_msg_handler.go b/internal/msg_transfer/logic/modify_msg_handler.go index 4cdff43fc..14990225d 100644 --- a/internal/msg_transfer/logic/modify_msg_handler.go +++ b/internal/msg_transfer/logic/modify_msg_handler.go @@ -1,7 +1,7 @@ package logic import ( - "Open_IM/pkg/base_info" + "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" @@ -61,7 +61,7 @@ func (mmc *ModifyMsgConsumerHandler) ModifyMsg(cMsg *sarama.ConsumerMessage, msg continue } if msgDataToMQ.MsgData.ContentType == constant.ReactionMessageModifier { - notification := &base_info.ReactionMessageModifierNotification{} + notification := &api_struct.ReactionMessageModifierNotification{} if err := json.Unmarshal(msgDataToMQ.MsgData.Content, notification); err != nil { continue } @@ -104,7 +104,7 @@ func (mmc *ModifyMsgConsumerHandler) ModifyMsg(cMsg *sarama.ConsumerMessage, msg } } } else if msgDataToMQ.MsgData.ContentType == constant.ReactionMessageDeleter { - notification := &base_info.ReactionMessageDeleteNotification{} + notification := &api_struct.ReactionMessageDeleteNotification{} if err := json.Unmarshal(msgDataToMQ.MsgData.Content, notification); err != nil { continue } @@ -116,7 +116,7 @@ func (mmc *ModifyMsgConsumerHandler) ModifyMsg(cMsg *sarama.ConsumerMessage, msg } -func UnMarshallSetReactionMsgContent(content []byte) (notification *base_info.ReactionMessageModifierNotification, err error) { +func UnMarshallSetReactionMsgContent(content []byte) (notification *api_struct.ReactionMessageModifierNotification, err error) { return notification, nil } diff --git a/internal/push/logic/push_to_client.go b/internal/push/logic/push_to_client.go index 5ed0bec53..03ab1a202 100644 --- a/internal/push/logic/push_to_client.go +++ b/internal/push/logic/push_to_client.go @@ -8,7 +8,6 @@ package logic import ( "Open_IM/internal/push" - utils2 "Open_IM/internal/utils" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" @@ -172,7 +171,7 @@ func MsgToSuperGroupUser(pushMsg *pbPush.PushMsgReq) { log.NewDebug(pushMsg.OperationID, utils.GetSelfFuncName(), "callback userIDList Resp", pushToUserIDList) } if len(pushToUserIDList) == 0 { - userIDList, err := utils2.GetGroupMemberUserIDList(context.Background(), pushMsg.MsgData.GroupID, pushMsg.OperationID) + userIDList, err := utils.GetGroupMemberUserIDList(context.Background(), pushMsg.MsgData.GroupID, pushMsg.OperationID) if err != nil { log.Error(pushMsg.OperationID, "GetGroupMemberUserIDList failed ", err.Error(), pushMsg.MsgData.GroupID) return diff --git a/internal/rpc/friend/friend.go b/internal/rpc/friend/friend.go index 50c8b43e5..212a04039 100644 --- a/internal/rpc/friend/friend.go +++ b/internal/rpc/friend/friend.go @@ -4,13 +4,10 @@ import ( chat "Open_IM/internal/rpc/msg" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/db/model" - "Open_IM/pkg/common/db/mysql" "Open_IM/pkg/common/log" "Open_IM/pkg/common/middleware" promePkg "Open_IM/pkg/common/prometheus" "Open_IM/pkg/common/token_verify" - "Open_IM/pkg/common/tools" "Open_IM/pkg/common/tracelog" "Open_IM/pkg/getcdv3" pbFriend "Open_IM/pkg/proto/friend" @@ -114,7 +111,7 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl if err := token_verify.CheckAccessV3(ctx, req.FromUserID); err != nil { return nil, err } - black := relation.Black{OwnerUserID: req.FromUserID, BlockUserID: req.ToUserID, OperatorUserID: tools.OpUserID(ctx)} + black := relation.Black{OwnerUserID: req.FromUserID, BlockUserID: req.ToUserID, OperatorUserID: utils.OpUserID(ctx)} if err := s.blackModel.Create(ctx, []*relation.Black{&black}); err != nil { return nil, err } @@ -222,7 +219,7 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF friendRequest.HandleResult = req.HandleResult friendRequest.HandleTime = time.Now() friendRequest.HandleMsg = req.HandleMsg - friendRequest.HandlerUserID = tools.OpUserID(ctx) + friendRequest.HandlerUserID = utils.OpUserID(ctx) err = relation.UpdateFriendApplication(friendRequest) if err != nil { return nil, err @@ -233,10 +230,10 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF //Establish friendship after find friend relationship not exists _, err := s.friendModel.Take(ctx, req.FromUserID, req.ToUserID) if errors.Is(err, gorm.ErrRecordNotFound) { - if err := s.friendModel.Create(ctx, []*relation.Friend{{OwnerUserID: req.FromUserID, FriendUserID: req.ToUserID, OperatorUserID: tools.OpUserID(ctx)}}); err != nil { + if err := s.friendModel.Create(ctx, []*relation.Friend{{OwnerUserID: req.FromUserID, FriendUserID: req.ToUserID, OperatorUserID: utils.OpUserID(ctx)}}); err != nil { return nil, err } - chat.FriendAddedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.FromUserID, req.ToUserID) + chat.FriendAddedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.FromUserID, req.ToUserID) } else if err != nil { return nil, err } @@ -292,7 +289,7 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFri if err := s.friendModel.UpdateRemark(ctx, req.FromUserID, req.ToUserID, req.Remark); err != nil { return nil, err } - chat.FriendRemarkSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.FromUserID, req.ToUserID) + chat.FriendRemarkSetNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.FromUserID, req.ToUserID) return resp, nil } diff --git a/internal/rpc/group/g.go b/internal/rpc/group/g.go index 1228a1c15..ef18feedf 100644 --- a/internal/rpc/group/g.go +++ b/internal/rpc/group/g.go @@ -3,7 +3,6 @@ package group import ( "Open_IM/pkg/common/constant" relation "Open_IM/pkg/common/db/mysql" - "Open_IM/pkg/common/tools" pbGroup "Open_IM/pkg/proto/group" sdk_ws "Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/utils" @@ -17,7 +16,7 @@ func getDBGroupRequest(ctx context.Context, req *pbGroup.GroupApplicationRespons dbGroupRequest = &relation.GroupRequest{} utils.CopyStructFields(&dbGroupRequest, req) dbGroupRequest.UserID = req.FromUserID - dbGroupRequest.HandleUserID = tools.OpUserID(ctx) + dbGroupRequest.HandleUserID = utils.OpUserID(ctx) dbGroupRequest.HandledTime = time.Now() return dbGroupRequest } @@ -29,7 +28,7 @@ func getDBGroupMember(ctx context.Context, groupID, userID string) (dbGroupMembe member.GroupID = groupID member.UserID = userID member.RoleLevel = constant.GroupOrdinaryUsers - member.OperatorUserID = tools.OpUserID(ctx) + member.OperatorUserID = utils.OpUserID(ctx) member.FaceURL = user.FaceURL member.Nickname = user.Nickname @@ -60,7 +59,7 @@ func genGroupID(ctx context.Context, groupID string) string { if groupID != "" { return groupID } - groupID = utils.Md5(tools.OperationID(ctx) + strconv.FormatInt(time.Now().UnixNano(), 10)) + groupID = utils.Md5(utils.OperationID(ctx) + strconv.FormatInt(time.Now().UnixNano(), 10)) bi := big.NewInt(0) bi.SetString(groupID[0:8], 16) groupID = bi.String() diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index 284ba2eb7..2826bf2bd 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -13,7 +13,6 @@ import ( "Open_IM/pkg/common/middleware" promePkg "Open_IM/pkg/common/prometheus" "Open_IM/pkg/common/token_verify" - "Open_IM/pkg/common/tools" "Open_IM/pkg/common/tracelog" cp "Open_IM/internal/utils" @@ -180,12 +179,12 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR return nil, err } } else { - opUserID := tools.OpUserID(ctx) + opUserID := utils.OpUserID(ctx) joinGroup := func(userID string, roleLevel int32) error { user := userMap[userID] groupMember := &relation.GroupMember{GroupID: group.GroupID, RoleLevel: roleLevel, OperatorUserID: opUserID, JoinSource: constant.JoinByInvitation, InviterUserID: opUserID} utils.CopyStructFields(&groupMember, user) - if err := CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), groupMember, group.Ex); err != nil { + if err := CallbackBeforeMemberJoinGroup(ctx, utils.OperationID(ctx), groupMember, group.Ex); err != nil { return err } groupMembers = append(groupMembers, groupMember) @@ -213,11 +212,11 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR if req.GroupInfo.GroupType == constant.SuperGroup { go func() { for _, userID := range userIDs { - chat.SuperGroupNotification(tools.OperationID(ctx), userID, userID) + chat.SuperGroupNotification(utils.OperationID(ctx), userID, userID) } }() } else { - chat.GroupCreatedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), group.GroupID, userIDs) + chat.GroupCreatedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), group.GroupID, userIDs) } return resp, nil } @@ -301,7 +300,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite } if group.NeedVerification == constant.AllNeedVerification { if !token_verify.IsAppManagerUid(ctx) { - opUserID := tools.OpUserID(ctx) + opUserID := utils.OpUserID(ctx) member, ok := memberMap[opUserID] if ok { return nil, constant.ErrNoPermission.Wrap("not in group") @@ -336,7 +335,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite return nil, err } for _, userID := range req.InvitedUserIDList { - chat.SuperGroupNotification(tools.OperationID(ctx), userID, userID) + chat.SuperGroupNotification(utils.OperationID(ctx), userID, userID) } } else { var groupMembers []*relation.GroupMember @@ -346,10 +345,10 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite utils.CopyStructFields(&member, user) member.GroupID = req.GroupID member.RoleLevel = constant.GroupOrdinaryUsers - member.OperatorUserID = tools.OpUserID(ctx) - member.InviterUserID = tools.OpUserID(ctx) + member.OperatorUserID = utils.OpUserID(ctx) + member.InviterUserID = utils.OpUserID(ctx) member.JoinSource = constant.JoinByInvitation - if err := CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), &member, group.Ex); err != nil { + if err := CallbackBeforeMemberJoinGroup(ctx, utils.OperationID(ctx), &member, group.Ex); err != nil { return nil, err } groupMembers = append(groupMembers, &member) @@ -357,7 +356,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite if err := s.GroupInterface.CreateGroupMember(ctx, groupMembers); err != nil { return nil, err } - chat.MemberInvitedNotification(tools.OperationID(ctx), req.GroupID, tools.OpUserID(ctx), req.Reason, req.InvitedUserIDList) + chat.MemberInvitedNotification(utils.OperationID(ctx), req.GroupID, utils.OpUserID(ctx), req.Reason, req.InvitedUserIDList) } return resp, nil } @@ -436,8 +435,8 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou var okUserIDList []string if groupInfo.GroupType != constant.SuperGroup { opFlag := 0 - if !token_verify.IsManagerUserID(tools.OpUserID(ctx)) { - opInfo, err := rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, tools.OpUserID(ctx)) + if !token_verify.IsManagerUserID(utils.OpUserID(ctx)) { + opInfo, err := rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, utils.OpUserID(ctx)) if err != nil { return nil, err } @@ -484,7 +483,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou err = relation.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, v) tracelog.SetCtxInfo(ctx, "RemoveGroupMember", err, "groupID", req.GroupID, "userID", v) if err != nil { - log.NewError(tools.OperationID(ctx), "RemoveGroupMember failed ", err.Error(), req.GroupID, v) + log.NewError(utils.OperationID(ctx), "RemoveGroupMember failed ", err.Error(), req.GroupID, v) resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: -1}) } else { resp.Id2ResultList = append(resp.Id2ResultList, &pbGroup.Id2Result{UserID: v, Result: 0}) @@ -494,7 +493,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou var reqPb pbUser.SetConversationReq var c pbConversation.Conversation for _, v := range okUserIDList { - reqPb.OperationID = tools.OperationID(ctx) + reqPb.OperationID = utils.OperationID(ctx) c.OwnerUserID = v c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType) c.ConversationType = constant.GroupChatType @@ -531,7 +530,7 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou } go func() { for _, v := range req.KickedUserIDList { - chat.SuperGroupNotification(tools.OperationID(ctx), v, v) + chat.SuperGroupNotification(utils.OperationID(ctx), v, v) } }() @@ -587,7 +586,7 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup. tracelog.SetCtxInfo(ctx, "GetRecvGroupApplicationList", nil, " FromUserID: ", req.FromUserID, "GroupApplicationList: ", reply) for _, v := range reply { node := open_im_sdk.GroupRequest{UserInfo: &open_im_sdk.PublicUserInfo{}, GroupInfo: &open_im_sdk.GroupInfo{}} - err := FillGroupInfoByGroupID(tools.OperationID(ctx), v.GroupID, node.GroupInfo) + err := FillGroupInfoByGroupID(utils.OperationID(ctx), v.GroupID, node.GroupInfo) if err != nil { if !errors.Is(errors.Unwrap(err), constant.ErrDismissedAlready) { errResult = err @@ -595,7 +594,7 @@ func (s *groupServer) GetGroupApplicationList(ctx context.Context, req *pbGroup. continue } tracelog.SetCtxInfo(ctx, "FillGroupInfoByGroupID ", nil, " groupID: ", v.GroupID, " groupInfo: ", node.GroupInfo) - err = FillPublicUserInfoByUserID(tools.OperationID(ctx), v.UserID, node.UserInfo) + err = FillPublicUserInfoByUserID(utils.OperationID(ctx), v.UserID, node.UserInfo) if err != nil { errResult = err continue @@ -640,7 +639,7 @@ func CheckPermission(ctx context.Context, groupID string, userID string) (err er func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup.GroupApplicationResponseReq) (*pbGroup.GroupApplicationResponseResp, error) { resp := &pbGroup.GroupApplicationResponseResp{} - if err := CheckPermission(ctx, req.GroupID, tools.OpUserID(ctx)); err != nil { + if err := CheckPermission(ctx, req.GroupID, utils.OpUserID(ctx)); err != nil { return nil, err } groupRequest := getDBGroupRequest(ctx, req) @@ -656,7 +655,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup if err != nil { return nil, err } - err = CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), member, groupInfo.Ex) + err = CallbackBeforeMemberJoinGroup(ctx, utils.OperationID(ctx), member, groupInfo.Ex) if err != nil { return nil, err } @@ -664,12 +663,12 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup if err != nil { return nil, err } - etcdCacheConn, err := fault_tolerant.GetDefaultConn(config.Config.RpcRegisterName.OpenImCacheName, tools.OperationID(ctx)) + etcdCacheConn, err := fault_tolerant.GetDefaultConn(config.Config.RpcRegisterName.OpenImCacheName, utils.OperationID(ctx)) if err != nil { return nil, err } cacheClient := pbCache.NewCacheClient(etcdCacheConn) - cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: tools.OperationID(ctx), GroupID: req.GroupID}) + cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: utils.OperationID(ctx), GroupID: req.GroupID}) if err != nil { return nil, err } @@ -696,7 +695,7 @@ func (s *groupServer) GroupApplicationResponse(ctx context.Context, req *pbGroup func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) (*pbGroup.JoinGroupResp, error) { resp := &pbGroup.JoinGroupResp{} - if _, err := relation.GetUserByUserID(tools.OpUserID(ctx)); err != nil { + if _, err := relation.GetUserByUserID(utils.OpUserID(ctx)); err != nil { return nil, err } groupInfo, err := rocksCache.GetGroupInfoFromCache(ctx, req.GroupID) @@ -709,17 +708,17 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) if groupInfo.NeedVerification == constant.Directly { if groupInfo.GroupType != constant.SuperGroup { - us, err := relation.GetUserByUserID(tools.OpUserID(ctx)) + us, err := relation.GetUserByUserID(utils.OpUserID(ctx)) if err != nil { return nil, err } //to group member - groupMember := relation.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: tools.OpUserID(ctx)} + groupMember := relation.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOrdinaryUsers, OperatorUserID: utils.OpUserID(ctx)} utils.CopyStructFields(&groupMember, us) - if err := CallbackBeforeMemberJoinGroup(ctx, tools.OperationID(ctx), &groupMember, groupInfo.Ex); err != nil { + if err := CallbackBeforeMemberJoinGroup(ctx, utils.OperationID(ctx), &groupMember, groupInfo.Ex); err != nil { return nil, err } - if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{tools.OpUserID(ctx)}); err != nil { + if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{utils.OpUserID(ctx)}); err != nil { return nil, err } err = relation.InsertIntoGroupMember(groupMember) @@ -735,8 +734,8 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) } var reqPb pbUser.SetConversationReq var c pbConversation.Conversation - reqPb.OperationID = tools.OperationID(ctx) - c.OwnerUserID = tools.OpUserID(ctx) + reqPb.OperationID = utils.OperationID(ctx) + c.OwnerUserID = utils.OpUserID(ctx) c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, sessionType) c.ConversationType = int32(sessionType) c.GroupID = req.GroupID @@ -750,7 +749,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) client := pbUser.NewUserClient(etcdConn) respPb, err := client.SetConversation(context.Background(), &reqPb) tracelog.SetCtxInfo(ctx, "SetConversation", err, "req", reqPb, "resp", respPb) - chat.MemberEnterDirectlyNotification(req.GroupID, tools.OpUserID(ctx), tools.OperationID(ctx)) + chat.MemberEnterDirectlyNotification(req.GroupID, utils.OpUserID(ctx), utils.OperationID(ctx)) return resp, nil } else { constant.SetErrorForResp(constant.ErrGroupTypeNotSupport, resp.CommonResp) @@ -758,7 +757,7 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) } } var groupRequest relation.GroupRequest - groupRequest.UserID = tools.OpUserID(ctx) + groupRequest.UserID = utils.OpUserID(ctx) groupRequest.ReqMsg = req.ReqMessage groupRequest.GroupID = req.GroupID groupRequest.JoinSource = req.JoinSource @@ -778,31 +777,31 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) return nil, err } if groupInfo.GroupType != constant.SuperGroup { - _, err = rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, tools.OpUserID(ctx)) + _, err = rocksCache.GetGroupMemberInfoFromCache(ctx, req.GroupID, utils.OpUserID(ctx)) if err != nil { return nil, err } - if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{tools.OpUserID(ctx)}); err != nil { + if err := s.DelGroupAndUserCache(ctx, req.GroupID, []string{utils.OpUserID(ctx)}); err != nil { return nil, err } - err = relation.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, tools.OpUserID(ctx)) + err = relation.DeleteGroupMemberByGroupIDAndUserID(req.GroupID, utils.OpUserID(ctx)) if err != nil { return nil, err } } else { - okUserIDList := []string{tools.OpUserID(ctx)} + okUserIDList := []string{utils.OpUserID(ctx)} if err := db.DB.RemoverUserFromSuperGroup(req.GroupID, okUserIDList); err != nil { return nil, err } } if groupInfo.GroupType != constant.SuperGroup { - _ = rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, tools.OpUserID(ctx)) + _ = rocksCache.DelGroupMemberInfoFromCache(ctx, req.GroupID, utils.OpUserID(ctx)) chat.MemberQuitNotification(req) } else { - _ = rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, tools.OpUserID(ctx)) + _ = rocksCache.DelJoinedSuperGroupIDListFromCache(ctx, utils.OpUserID(ctx)) _ = rocksCache.DelGroupMemberListHashFromCache(ctx, req.GroupID) - chat.SuperGroupNotification(tools.OperationID(ctx), tools.OpUserID(ctx), tools.OpUserID(ctx)) + chat.SuperGroupNotification(utils.OperationID(ctx), utils.OpUserID(ctx), utils.OpUserID(ctx)) } return resp, nil } @@ -871,7 +870,7 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf var groupInfo relation.Group utils.CopyStructFields(&groupInfo, req.GroupInfoForSet) if req.GroupInfoForSet.Notification != "" { - groupInfo.NotificationUserID = tools.OpUserID(ctx) + groupInfo.NotificationUserID = utils.OpUserID(ctx) groupInfo.NotificationUpdateTime = time.Now() } if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupInfoForSet.GroupID); err != nil { @@ -882,11 +881,11 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf return nil, err } if changedType != 0 { - chat.GroupInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupInfoForSet.GroupID, groupName, notification, introduction, faceURL, req.GroupInfoForSet.NeedVerification) + chat.GroupInfoSetNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupInfoForSet.GroupID, groupName, notification, introduction, faceURL, req.GroupInfoForSet.NeedVerification) } if req.GroupInfoForSet.Notification != "" { //get group member user id - getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: tools.OperationID(ctx), GroupID: req.GroupInfoForSet.GroupID} + getGroupMemberIDListFromCacheReq := &pbCache.GetGroupMemberIDListFromCacheReq{OperationID: utils.OperationID(ctx), GroupID: req.GroupInfoForSet.GroupID} etcdConn, err := getcdv3.GetConn(ctx, config.Config.RpcRegisterName.OpenImCacheName) if err != nil { return nil, err @@ -901,13 +900,13 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf } var conversationReq pbConversation.ModifyConversationFieldReq conversation := pbConversation.Conversation{ - OwnerUserID: tools.OpUserID(ctx), + OwnerUserID: utils.OpUserID(ctx), ConversationID: utils.GetConversationIDBySessionType(req.GroupInfoForSet.GroupID, constant.GroupChatType), ConversationType: constant.GroupChatType, GroupID: req.GroupInfoForSet.GroupID, } conversationReq.Conversation = &conversation - conversationReq.OperationID = tools.OperationID(ctx) + conversationReq.OperationID = utils.OperationID(ctx) conversationReq.FieldType = constant.FieldGroupAtType conversation.GroupAtType = constant.GroupNotification conversationReq.UserIDList = cacheResp.UserIDList @@ -1020,7 +1019,7 @@ func (s *groupServer) GetGroupMembersCMS(ctx context.Context, req *pbGroup.GetGr if err != nil { return nil, err } - log.NewInfo(tools.OperationID(ctx), groupMembersCount) + log.NewInfo(utils.OperationID(ctx), groupMembersCount) resp.MemberNums = int32(groupMembersCount) for _, groupMember := range groupMembers { member := open_im_sdk.GroupMemberFullInfo{} @@ -1065,7 +1064,7 @@ func (s *groupServer) GetUserReqApplicationList(ctx context.Context, req *pbGrou func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGroupReq) (*pbGroup.DismissGroupResp, error) { resp := &pbGroup.DismissGroupResp{} - if !token_verify.IsManagerUserID(tools.OpUserID(ctx)) && !relation.IsGroupOwnerAdmin(req.GroupID, tools.OpUserID(ctx)) { + if !token_verify.IsManagerUserID(utils.OpUserID(ctx)) && !relation.IsGroupOwnerAdmin(req.GroupID, utils.OpUserID(ctx)) { return nil, utils.Wrap(constant.ErrIdentity, "") } @@ -1093,7 +1092,7 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou var reqPb pbUser.SetConversationReq var c pbConversation.Conversation for _, v := range memberList { - reqPb.OperationID = tools.OperationID(ctx) + reqPb.OperationID = utils.OperationID(ctx) c.OwnerUserID = v.UserID c.ConversationID = utils.GetConversationIDBySessionType(req.GroupID, constant.GroupChatType) c.ConversationType = constant.GroupChatType @@ -1122,7 +1121,7 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGroupMemberReq) (*pbGroup.MuteGroupMemberResp, error) { resp := &pbGroup.MuteGroupMemberResp{} - opFlag, err := s.getGroupUserLevel(req.GroupID, tools.OpUserID(ctx)) + opFlag, err := s.getGroupUserLevel(req.GroupID, utils.OpUserID(ctx)) if err != nil { return nil, err } @@ -1150,14 +1149,14 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou if err != nil { return nil, err } - chat.GroupMemberMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID, req.MutedSeconds) + chat.GroupMemberMutedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID, req.UserID, req.MutedSeconds) return resp, nil } func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.CancelMuteGroupMemberReq) (*pbGroup.CancelMuteGroupMemberResp, error) { resp := &pbGroup.CancelMuteGroupMemberResp{} - opFlag, err := s.getGroupUserLevel(req.GroupID, tools.OpUserID(ctx)) + opFlag, err := s.getGroupUserLevel(req.GroupID, utils.OpUserID(ctx)) if err != nil { return nil, err } @@ -1185,14 +1184,14 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.Ca if err != nil { return nil, err } - chat.GroupMemberCancelMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID) + chat.GroupMemberCancelMutedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID, req.UserID) return resp, nil } func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq) (*pbGroup.MuteGroupResp, error) { resp := &pbGroup.MuteGroupResp{} - opFlag, err := s.getGroupUserLevel(req.GroupID, tools.OpUserID(ctx)) + opFlag, err := s.getGroupUserLevel(req.GroupID, utils.OpUserID(ctx)) if err != nil { return nil, err } @@ -1225,14 +1224,14 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq) return nil, err } - chat.GroupMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID) + chat.GroupMutedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID) return resp, nil } func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMuteGroupReq) (*pbGroup.CancelMuteGroupResp, error) { resp := &pbGroup.CancelMuteGroupResp{} - opFlag, err := s.getGroupUserLevel(req.GroupID, tools.OpUserID(ctx)) + opFlag, err := s.getGroupUserLevel(req.GroupID, utils.OpUserID(ctx)) if err != nil { return nil, err } @@ -1252,7 +1251,7 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu // errMsg := req.OperationID + " mutedInfo.RoleLevel == constant.GroupAdmin " + req.GroupID + req.OpUserID + err.Error() // return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: errMsg}}, nil //} - log.Debug(tools.OperationID(ctx), "UpdateGroupInfoDefaultZero ", req.GroupID, map[string]interface{}{"status": constant.GroupOk}) + log.Debug(utils.OperationID(ctx), "UpdateGroupInfoDefaultZero ", req.GroupID, map[string]interface{}{"status": constant.GroupOk}) if err := rocksCache.DelGroupInfoFromCache(ctx, req.GroupID); err != nil { return nil, err } @@ -1260,14 +1259,14 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu if err != nil { return nil, err } - chat.GroupCancelMutedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID) + chat.GroupCancelMutedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID) return resp, nil } func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.SetGroupMemberNicknameReq) (*pbGroup.SetGroupMemberNicknameResp, error) { resp := &pbGroup.SetGroupMemberNicknameResp{} - if tools.OpUserID(ctx) != req.UserID && !token_verify.IsManagerUserID(tools.OpUserID(ctx)) { + if utils.OpUserID(ctx) != req.UserID && !token_verify.IsManagerUserID(utils.OpUserID(ctx)) { return nil, utils.Wrap(constant.ErrIdentity, "") } cbReq := &pbGroup.SetGroupMemberInfoReq{ @@ -1299,7 +1298,7 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S if err := relation.UpdateGroupMemberInfo(groupMemberInfo); err != nil { return nil, err } - chat.GroupMemberInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID) + chat.GroupMemberInfoSetNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID, req.UserID) return resp, nil } @@ -1338,13 +1337,13 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr switch req.RoleLevel.Value { case constant.GroupOrdinaryUsers: //msg.GroupMemberRoleLevelChangeNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, constant.GroupMemberSetToOrdinaryUserNotification) - chat.GroupMemberInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID) + chat.GroupMemberInfoSetNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID, req.UserID) case constant.GroupAdmin, constant.GroupOwner: //msg.GroupMemberRoleLevelChangeNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, constant.GroupMemberSetToAdminNotification) - chat.GroupMemberInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID) + chat.GroupMemberInfoSetNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID, req.UserID) } } else { - chat.GroupMemberInfoSetNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.GroupID, req.UserID) + chat.GroupMemberInfoSetNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.GroupID, req.UserID) } return resp, nil } diff --git a/internal/rpc/msg/extend_msg.notification.go b/internal/rpc/msg/extend_msg.notification.go index 433ecfd65..dc9089f0d 100644 --- a/internal/rpc/msg/extend_msg.notification.go +++ b/internal/rpc/msg/extend_msg.notification.go @@ -1,7 +1,7 @@ package msg import ( - "Open_IM/pkg/base_info" + "Open_IM/pkg/api_struct" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" @@ -14,7 +14,7 @@ import ( func ExtendMessageUpdatedNotification(operationID, sendID string, sourceID string, sessionType int32, req *msg.SetMessageReactionExtensionsReq, resp *msg.SetMessageReactionExtensionsResp, isHistory bool, isReactionFromCache bool) { - var m base_info.ReactionMessageModifierNotification + var m api_struct.ReactionMessageModifierNotification m.SourceID = req.SourceID m.OpUserID = req.OpUserID m.SessionType = req.SessionType @@ -37,7 +37,7 @@ func ExtendMessageUpdatedNotification(operationID, sendID string, sourceID strin } func ExtendMessageDeleteNotification(operationID, sendID string, sourceID string, sessionType int32, req *msg.DeleteMessageListReactionExtensionsReq, resp *msg.DeleteMessageListReactionExtensionsResp, isHistory bool, isReactionFromCache bool) { - var m base_info.ReactionMessageDeleteNotification + var m api_struct.ReactionMessageDeleteNotification m.SourceID = req.SourceID m.OpUserID = req.OpUserID m.SessionType = req.SessionType diff --git a/internal/rpc/msg/group_notification.go b/internal/rpc/msg/group_notification.go index ea5e14db2..5d8521afa 100644 --- a/internal/rpc/msg/group_notification.go +++ b/internal/rpc/msg/group_notification.go @@ -6,7 +6,6 @@ import ( imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" - "Open_IM/pkg/common/tools" utils2 "Open_IM/pkg/common/utils" pbGroup "Open_IM/pkg/proto/group" open_im_sdk "Open_IM/pkg/proto/sdk_ws" @@ -389,23 +388,23 @@ func JoinGroupApplicationNotification(ctx context.Context, req *pbGroup.JoinGrou JoinGroupApplicationTips := open_im_sdk.JoinGroupApplicationTips{Group: &open_im_sdk.GroupInfo{}, Applicant: &open_im_sdk.PublicUserInfo{}} err := setGroupInfo(req.GroupID, JoinGroupApplicationTips.Group) if err != nil { - log.Error(tools.OperationID(ctx), "setGroupInfo failed ", err.Error(), req.GroupID) + log.Error(utils.OperationID(ctx), "setGroupInfo failed ", err.Error(), req.GroupID) return } - if err = setPublicUserInfo(tools.OpUserID(ctx), JoinGroupApplicationTips.Applicant); err != nil { - log.Error(tools.OperationID(ctx), "setPublicUserInfo failed ", err.Error(), tools.OpUserID(ctx)) + if err = setPublicUserInfo(utils.OpUserID(ctx), JoinGroupApplicationTips.Applicant); err != nil { + log.Error(utils.OperationID(ctx), "setPublicUserInfo failed ", err.Error(), utils.OpUserID(ctx)) return } JoinGroupApplicationTips.ReqMsg = req.ReqMessage managerList, err := imdb.GetOwnerManagerByGroupID(req.GroupID) if err != nil { - log.NewError(tools.OperationID(ctx), "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID) + log.NewError(utils.OperationID(ctx), "GetOwnerManagerByGroupId failed ", err.Error(), req.GroupID) return } for _, v := range managerList { - groupNotification(constant.JoinGroupApplicationNotification, &JoinGroupApplicationTips, tools.OpUserID(ctx), "", v.UserID, tools.OperationID(ctx)) - log.NewInfo(tools.OperationID(ctx), "Notification ", v) + groupNotification(constant.JoinGroupApplicationNotification, &JoinGroupApplicationTips, utils.OpUserID(ctx), "", v.UserID, utils.OperationID(ctx)) + log.NewInfo(utils.OperationID(ctx), "Notification ", v) } } diff --git a/internal/rpc/msg/send_msg.go b/internal/rpc/msg/send_msg.go index bbeb289b8..1caebccd9 100644 --- a/internal/rpc/msg/send_msg.go +++ b/internal/rpc/msg/send_msg.go @@ -1,7 +1,6 @@ package msg import ( - utils2 "Open_IM/internal/utils" "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" @@ -177,7 +176,7 @@ func (rpc *rpcChat) messageVerification(ctx context.Context, data *pbChat.SendMs return true, 0, "", nil } case constant.GroupChatType: - userIDList, err := utils2.GetGroupMemberUserIDList(ctx, data.MsgData.GroupID, data.OperationID) + userIDList, err := utils.GetGroupMemberUserIDList(ctx, data.MsgData.GroupID, data.OperationID) if err != nil { errMsg := data.OperationID + err.Error() log.NewError(data.OperationID, errMsg) @@ -251,7 +250,7 @@ func (rpc *rpcChat) messageVerification(ctx context.Context, data *pbChat.SendMs if groupInfo.GroupType == constant.SuperGroup { return true, 0, "", nil } else { - userIDList, err := utils2.GetGroupMemberUserIDList(ctx, data.MsgData.GroupID, data.OperationID) + userIDList, err := utils.GetGroupMemberUserIDList(ctx, data.MsgData.GroupID, data.OperationID) if err != nil { errMsg := data.OperationID + err.Error() log.NewError(data.OperationID, errMsg) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index 6edb04f42..2711c056c 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -9,7 +9,6 @@ import ( "Open_IM/pkg/common/log" promePkg "Open_IM/pkg/common/prometheus" "Open_IM/pkg/common/token_verify" - "Open_IM/pkg/common/tools" "Open_IM/pkg/getcdv3" pbFriend "Open_IM/pkg/proto/friend" pbGroup "Open_IM/pkg/proto/group" @@ -23,7 +22,6 @@ import ( grpcPrometheus "github.com/grpc-ecosystem/go-grpc-prometheus" - utils2 "Open_IM/internal/utils" "google.golang.org/grpc" ) @@ -173,7 +171,7 @@ func (s *userServer) GetUsersInfo(ctx context.Context, req *pbUser.GetUsersInfoR return nil, err } for _, v := range users { - n, err := utils2.NewDBUser(v).Convert() + n, err := utils.NewDBUser(v).Convert() if err != nil { return nil, err } @@ -196,7 +194,7 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI } oldNickname = u.Nickname } - user, err := utils2.NewPBUser(req.UserInfo).Convert() + user, err := utils.NewPBUser(req.UserInfo).Convert() if err != nil { return nil, err } @@ -216,16 +214,16 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI } go func() { for _, v := range rpcResp.FriendInfoList { - chat.FriendInfoUpdatedNotification(tools.OperationID(ctx), req.UserInfo.UserID, v.FriendUser.UserID, tools.OpUserID(ctx)) + chat.FriendInfoUpdatedNotification(utils.OperationID(ctx), req.UserInfo.UserID, v.FriendUser.UserID, utils.OpUserID(ctx)) } }() - chat.UserInfoUpdatedNotification(tools.OperationID(ctx), tools.OpUserID(ctx), req.UserInfo.UserID) + chat.UserInfoUpdatedNotification(utils.OperationID(ctx), utils.OpUserID(ctx), req.UserInfo.UserID) if req.UserInfo.FaceURL != "" { - s.SyncJoinedGroupMemberFaceURL(ctx, req.UserInfo.UserID, req.UserInfo.FaceURL, tools.OperationID(ctx), tools.OpUserID(ctx)) + s.SyncJoinedGroupMemberFaceURL(ctx, req.UserInfo.UserID, req.UserInfo.FaceURL, utils.OperationID(ctx), utils.OpUserID(ctx)) } if req.UserInfo.Nickname != "" { - s.SyncJoinedGroupMemberNickname(ctx, req.UserInfo.UserID, req.UserInfo.Nickname, oldNickname, tools.OperationID(ctx), tools.OpUserID(ctx)) + s.SyncJoinedGroupMemberNickname(ctx, req.UserInfo.UserID, req.UserInfo.Nickname, oldNickname, utils.OperationID(ctx), utils.OpUserID(ctx)) } return &resp, nil } @@ -238,13 +236,13 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.Se if err != nil { return nil, err } - chat.UserInfoUpdatedNotification(tools.OperationID(ctx), req.UserID, req.UserID) + chat.UserInfoUpdatedNotification(utils.OperationID(ctx), req.UserID, req.UserID) return &resp, nil } func (s *userServer) AccountCheck(ctx context.Context, req *pbUser.AccountCheckReq) (*pbUser.AccountCheckResp, error) { resp := pbUser.AccountCheckResp{} - err := token_verify.CheckManagerUserID(ctx, tools.OpUserID(ctx)) + err := token_verify.CheckManagerUserID(ctx, utils.OpUserID(ctx)) if err != nil { return nil, err } @@ -279,7 +277,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb return nil, err } resp.Total = 1 - u1, err := utils2.NewDBUser(u).Convert() + u1, err := utils.NewDBUser(u).Convert() if err != nil { return nil, err } @@ -294,7 +292,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb } resp.Total = int32(total) for _, v := range usersDB { - u1, err := utils2.NewDBUser(v).Convert() + u1, err := utils.NewDBUser(v).Convert() if err != nil { return nil, err } @@ -308,7 +306,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb } resp.Total = int32(total) for _, v := range usersDB { - u1, err := utils2.NewDBUser(v).Convert() + u1, err := utils.NewDBUser(v).Convert() if err != nil { return nil, err } @@ -325,7 +323,7 @@ func (s *userServer) GetUsers(ctx context.Context, req *pbUser.GetUsersReq) (*pb resp.Total = int32(total) for _, userDB := range usersDB { - u, err := utils2.NewDBUser(userDB).Convert() + u, err := utils.NewDBUser(userDB).Convert() if err != nil { return nil, err } diff --git a/internal/utils/get_server_ip_test.go b/internal/utils/get_server_ip_test.go deleted file mode 100644 index d4b585bf7..000000000 --- a/internal/utils/get_server_ip_test.go +++ /dev/null @@ -1 +0,0 @@ -package utils diff --git a/internal/utils/utils.go b/internal/utils/utils.go deleted file mode 100644 index 73ebbf127..000000000 --- a/internal/utils/utils.go +++ /dev/null @@ -1,49 +0,0 @@ -package utils - -import ( - "encoding/json" - "github.com/golang/protobuf/jsonpb" - "github.com/golang/protobuf/proto" - "reflect" -) - -func JsonDataList(resp interface{}) []map[string]interface{} { - var list []proto.Message - if reflect.TypeOf(resp).Kind() == reflect.Slice { - s := reflect.ValueOf(resp) - for i := 0; i < s.Len(); i++ { - ele := s.Index(i) - list = append(list, ele.Interface().(proto.Message)) - } - } - - result := make([]map[string]interface{}, 0) - for _, v := range list { - m := ProtoToMap(v, false) - result = append(result, m) - } - return result -} - -func JsonDataOne(pb proto.Message) map[string]interface{} { - return ProtoToMap(pb, false) -} - -func ProtoToMap(pb proto.Message, idFix bool) map[string]interface{} { - marshaler := jsonpb.Marshaler{ - OrigName: true, - EnumsAsInts: false, - EmitDefaults: false, - } - - s, _ := marshaler.MarshalToString(pb) - out := make(map[string]interface{}) - json.Unmarshal([]byte(s), &out) - if idFix { - if _, ok := out["id"]; ok { - out["_id"] = out["id"] - delete(out, "id") - } - } - return out -} diff --git a/pkg/base_info/auth_api_struct.go b/pkg/api_struct/auth_api_struct.go similarity index 99% rename from pkg/base_info/auth_api_struct.go rename to pkg/api_struct/auth_api_struct.go index 93eebc2b5..e5b50730c 100644 --- a/pkg/base_info/auth_api_struct.go +++ b/pkg/api_struct/auth_api_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct //UserID string `protobuf:"bytes,1,opt,name=UserID" json:"UserID,omitempty"` // Nickname string `protobuf:"bytes,2,opt,name=Nickname" json:"Nickname,omitempty"` diff --git a/pkg/base_info/aws_api_struct.go b/pkg/api_struct/aws_api_struct.go similarity index 96% rename from pkg/base_info/aws_api_struct.go rename to pkg/api_struct/aws_api_struct.go index ebd26021e..0479080e4 100644 --- a/pkg/base_info/aws_api_struct.go +++ b/pkg/api_struct/aws_api_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct type AwsStorageCredentialReq struct { OperationID string `json:"operationID"` diff --git a/pkg/base_info/client_init.go b/pkg/api_struct/client_init.go similarity index 95% rename from pkg/base_info/client_init.go rename to pkg/api_struct/client_init.go index 47cfdcdea..4ceed6221 100644 --- a/pkg/base_info/client_init.go +++ b/pkg/api_struct/client_init.go @@ -1,4 +1,4 @@ -package base_info +package api_struct type SetClientInitConfigReq struct { OperationID string `json:"operationID" binding:"required"` diff --git a/pkg/base_info/common.go b/pkg/api_struct/common.go similarity index 93% rename from pkg/base_info/common.go rename to pkg/api_struct/common.go index a90a845a3..e17c6f036 100644 --- a/pkg/base_info/common.go +++ b/pkg/api_struct/common.go @@ -1,4 +1,4 @@ -package base_info +package api_struct type RequestPagination struct { PageNumber int `json:"pageNumber" binding:"required"` diff --git a/pkg/base_info/conversation_api_struct.go b/pkg/api_struct/conversation_api_struct.go similarity index 99% rename from pkg/base_info/conversation_api_struct.go rename to pkg/api_struct/conversation_api_struct.go index 08353e2ed..da4b5ced9 100644 --- a/pkg/base_info/conversation_api_struct.go +++ b/pkg/api_struct/conversation_api_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct type OptResult struct { ConversationID string `json:"conversationID"` diff --git a/pkg/base_info/cos_api_struct.go b/pkg/api_struct/cos_api_struct.go similarity index 95% rename from pkg/base_info/cos_api_struct.go rename to pkg/api_struct/cos_api_struct.go index e35931ad9..0c9e92a5b 100644 --- a/pkg/base_info/cos_api_struct.go +++ b/pkg/api_struct/cos_api_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct import sts "github.com/tencentyun/qcloud-cos-sts-sdk/go" diff --git a/pkg/base_info/friend_api_struct.go b/pkg/api_struct/friend_api_struct.go similarity index 99% rename from pkg/base_info/friend_api_struct.go rename to pkg/api_struct/friend_api_struct.go index 8c6da6b53..b89ba3208 100644 --- a/pkg/base_info/friend_api_struct.go +++ b/pkg/api_struct/friend_api_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct //type ParamsCommFriend struct { // OperationID string `json:"operationID" binding:"required"` diff --git a/pkg/base_info/group_api_struct.go b/pkg/api_struct/group_api_struct.go similarity index 99% rename from pkg/base_info/group_api_struct.go rename to pkg/api_struct/group_api_struct.go index e002ea203..b15458d79 100644 --- a/pkg/base_info/group_api_struct.go +++ b/pkg/api_struct/group_api_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct import ( open_im_sdk "Open_IM/pkg/proto/sdk_ws" diff --git a/pkg/base_info/manage_api_struct.go b/pkg/api_struct/manage_api_struct.go similarity index 99% rename from pkg/base_info/manage_api_struct.go rename to pkg/api_struct/manage_api_struct.go index 9837842fb..4e6c6977b 100644 --- a/pkg/base_info/manage_api_struct.go +++ b/pkg/api_struct/manage_api_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct import ( pbRelay "Open_IM/pkg/proto/relay" diff --git a/pkg/base_info/msg.go b/pkg/api_struct/msg.go similarity index 99% rename from pkg/base_info/msg.go rename to pkg/api_struct/msg.go index 5a7c7f538..6451f8542 100644 --- a/pkg/base_info/msg.go +++ b/pkg/api_struct/msg.go @@ -1,4 +1,4 @@ -package base_info +package api_struct import ( "Open_IM/pkg/proto/msg" diff --git a/pkg/base_info/office_struct.go b/pkg/api_struct/office_struct.go similarity index 99% rename from pkg/base_info/office_struct.go rename to pkg/api_struct/office_struct.go index 1e8e174bd..3eeb1ed3f 100644 --- a/pkg/base_info/office_struct.go +++ b/pkg/api_struct/office_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct import ( pbOffice "Open_IM/pkg/proto/office" diff --git a/pkg/base_info/organization_api_struct.go b/pkg/api_struct/organization_api_struct.go similarity index 99% rename from pkg/base_info/organization_api_struct.go rename to pkg/api_struct/organization_api_struct.go index 8daef2070..c6c1d8327 100644 --- a/pkg/base_info/organization_api_struct.go +++ b/pkg/api_struct/organization_api_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct import open_im_sdk "Open_IM/pkg/proto/sdk_ws" diff --git a/pkg/base_info/oss_api_struct.go b/pkg/api_struct/oss_api_struct.go similarity index 96% rename from pkg/base_info/oss_api_struct.go rename to pkg/api_struct/oss_api_struct.go index 621d18820..9cbac79f8 100644 --- a/pkg/base_info/oss_api_struct.go +++ b/pkg/api_struct/oss_api_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct type OSSCredentialReq struct { OperationID string `json:"operationID"` diff --git a/pkg/base_info/pagination.go b/pkg/api_struct/pagination.go similarity index 88% rename from pkg/base_info/pagination.go rename to pkg/api_struct/pagination.go index d73725632..717664cb1 100644 --- a/pkg/base_info/pagination.go +++ b/pkg/api_struct/pagination.go @@ -1,4 +1,4 @@ -package base_info +package api_struct type Pagination struct { PageNumber int32 `json:"pageNumber" binding:"required"` diff --git a/pkg/base_info/public_struct.go b/pkg/api_struct/public_struct.go similarity index 99% rename from pkg/base_info/public_struct.go rename to pkg/api_struct/public_struct.go index ba7195d62..e5e8519bd 100644 --- a/pkg/base_info/public_struct.go +++ b/pkg/api_struct/public_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct import ( "net/http" diff --git a/pkg/base_info/super_group.go b/pkg/api_struct/super_group.go similarity index 92% rename from pkg/base_info/super_group.go rename to pkg/api_struct/super_group.go index 8ea24e014..449892e75 100644 --- a/pkg/base_info/super_group.go +++ b/pkg/api_struct/super_group.go @@ -1,4 +1,4 @@ -package base_info +package api_struct type GetJoinedSuperGroupListReq struct { GetJoinedGroupListReq diff --git a/pkg/base_info/swagger_example.go b/pkg/api_struct/swagger_example.go similarity index 93% rename from pkg/base_info/swagger_example.go rename to pkg/api_struct/swagger_example.go index b56f26276..8c5598614 100644 --- a/pkg/base_info/swagger_example.go +++ b/pkg/api_struct/swagger_example.go @@ -1,4 +1,4 @@ -package base_info +package api_struct type Swagger400Resp struct { ErrCode int32 `json:"errCode" example:"400"` diff --git a/pkg/base_info/third_api_struct.go b/pkg/api_struct/third_api_struct.go similarity index 99% rename from pkg/base_info/third_api_struct.go rename to pkg/api_struct/third_api_struct.go index 0f1480c12..258c19a42 100644 --- a/pkg/base_info/third_api_struct.go +++ b/pkg/api_struct/third_api_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct import "mime/multipart" diff --git a/pkg/base_info/user_api_struct.go b/pkg/api_struct/user_api_struct.go similarity index 98% rename from pkg/base_info/user_api_struct.go rename to pkg/api_struct/user_api_struct.go index 09e19bd6b..7cd165fbb 100644 --- a/pkg/base_info/user_api_struct.go +++ b/pkg/api_struct/user_api_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct import ( open_im_sdk "Open_IM/pkg/proto/sdk_ws" diff --git a/pkg/base_info/work_moments_struct.go b/pkg/api_struct/work_moments_struct.go similarity index 99% rename from pkg/base_info/work_moments_struct.go rename to pkg/api_struct/work_moments_struct.go index 1e09d849f..ce7fe59a4 100644 --- a/pkg/base_info/work_moments_struct.go +++ b/pkg/api_struct/work_moments_struct.go @@ -1,4 +1,4 @@ -package base_info +package api_struct import "Open_IM/pkg/proto/office" diff --git a/pkg/cms_api_struct/admin.go b/pkg/cms_struct/admin.go similarity index 93% rename from pkg/cms_api_struct/admin.go rename to pkg/cms_struct/admin.go index 0cde6c978..55e9f5bfa 100644 --- a/pkg/cms_api_struct/admin.go +++ b/pkg/cms_struct/admin.go @@ -1,7 +1,7 @@ -package cms_api_struct +package cms_struct import ( - "Open_IM/pkg/base_info" + "Open_IM/pkg/api_struct" server_api_params "Open_IM/pkg/proto/sdk_ws" ) @@ -47,10 +47,10 @@ type ReduceUserRegisterAddFriendIDListResponse struct { type GetUserRegisterAddFriendIDListRequest struct { OperationID string `json:"operationID" binding:"required"` - base_info.RequestPagination + api_struct.RequestPagination } type GetUserRegisterAddFriendIDListResponse struct { Users []*server_api_params.UserInfo `json:"users"` - base_info.ResponsePagination + api_struct.ResponsePagination } diff --git a/pkg/cms_api_struct/common.go b/pkg/cms_struct/common.go similarity index 91% rename from pkg/cms_api_struct/common.go rename to pkg/cms_struct/common.go index cbce2dfa3..264ec7942 100644 --- a/pkg/cms_api_struct/common.go +++ b/pkg/cms_struct/common.go @@ -1,4 +1,4 @@ -package cms_api_struct +package cms_struct type RequestPagination struct { PageNumber int `json:"pageNumber" binding:"required"` diff --git a/pkg/cms_api_struct/friend.go b/pkg/cms_struct/friend.go similarity index 96% rename from pkg/cms_api_struct/friend.go rename to pkg/cms_struct/friend.go index ce3af6ddc..40b8dd843 100644 --- a/pkg/cms_api_struct/friend.go +++ b/pkg/cms_struct/friend.go @@ -1,4 +1,4 @@ -package cms_api_struct +package cms_struct type GetFriendsReq struct { OperationID string `json:"operationID"` diff --git a/pkg/cms_api_struct/group.go b/pkg/cms_struct/group.go similarity index 99% rename from pkg/cms_api_struct/group.go rename to pkg/cms_struct/group.go index 00769e80f..8acd4d459 100644 --- a/pkg/cms_api_struct/group.go +++ b/pkg/cms_struct/group.go @@ -1,4 +1,4 @@ -package cms_api_struct +package cms_struct type GroupResponse struct { GroupOwnerName string `json:"GroupOwnerName"` diff --git a/pkg/cms_api_struct/message_cms.go b/pkg/cms_struct/message_cms.go similarity index 98% rename from pkg/cms_api_struct/message_cms.go rename to pkg/cms_struct/message_cms.go index c537ae228..27033e72f 100644 --- a/pkg/cms_api_struct/message_cms.go +++ b/pkg/cms_struct/message_cms.go @@ -1,4 +1,4 @@ -package cms_api_struct +package cms_struct import ( pbCommon "Open_IM/pkg/proto/sdk_ws" diff --git a/pkg/cms_api_struct/statistics.go b/pkg/cms_struct/statistics.go similarity index 99% rename from pkg/cms_api_struct/statistics.go rename to pkg/cms_struct/statistics.go index 0fd0eb76b..f1dc2b0c9 100644 --- a/pkg/cms_api_struct/statistics.go +++ b/pkg/cms_struct/statistics.go @@ -1,4 +1,4 @@ -package cms_api_struct +package cms_struct type GetStatisticsRequest struct { From string `json:"from" binding:"required"` diff --git a/pkg/cms_api_struct/user.go b/pkg/cms_struct/user.go similarity index 98% rename from pkg/cms_api_struct/user.go rename to pkg/cms_struct/user.go index 5390928d8..400514ac9 100644 --- a/pkg/cms_api_struct/user.go +++ b/pkg/cms_struct/user.go @@ -1,4 +1,4 @@ -package cms_api_struct +package cms_struct type UserResponse struct { FaceURL string `json:"faceURL"` diff --git a/pkg/common/callback/callback.go b/pkg/common/callback/callback.go index fa19e7961..3224f7853 100644 --- a/pkg/common/callback/callback.go +++ b/pkg/common/callback/callback.go @@ -10,11 +10,6 @@ func GetContent(msg *server_api_params.MsgData) string { if msg.ContentType >= constant.NotificationBegin && msg.ContentType <= constant.NotificationEnd { var tips server_api_params.TipsComm _ = proto.Unmarshal(msg.Content, &tips) - //marshaler := jsonpb.Marshaler{ - // OrigName: true, - // EnumsAsInts: false, - // EmitDefaults: false, - //} content := tips.JsonDetail return content } else { diff --git a/pkg/common/token_verify/jwt_token.go b/pkg/common/token_verify/jwt_token.go index 9f65b75ed..9ee1b38e3 100644 --- a/pkg/common/token_verify/jwt_token.go +++ b/pkg/common/token_verify/jwt_token.go @@ -5,7 +5,6 @@ import ( "Open_IM/pkg/common/constant" commonDB "Open_IM/pkg/common/db" "Open_IM/pkg/common/log" - "Open_IM/pkg/common/tools" "Open_IM/pkg/common/tracelog" "Open_IM/pkg/utils" "context" @@ -160,7 +159,7 @@ func CheckAccess(ctx context.Context, OpUserID string, OwnerUserID string) bool } func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) { - opUserID := tools.OpUserID(ctx) + opUserID := utils.OpUserID(ctx) defer func() { tracelog.SetCtxInfo(ctx, utils.GetFuncName(1), err, "OpUserID", opUserID, "ownerUserID", ownerUserID) }() @@ -174,11 +173,11 @@ func CheckAccessV3(ctx context.Context, ownerUserID string) (err error) { } func IsAppManagerUid(ctx context.Context) bool { - return utils.IsContain(tools.OpUserID(ctx), config.Config.Manager.AppManagerUid) + return utils.IsContain(utils.OpUserID(ctx), config.Config.Manager.AppManagerUid) } func CheckAdmin(ctx context.Context) error { - if utils.IsContain(tools.OpUserID(ctx), config.Config.Manager.AppManagerUid) { + if utils.IsContain(utils.OpUserID(ctx), config.Config.Manager.AppManagerUid) { return nil } return constant.ErrIdentity.Wrap() diff --git a/pkg/common/tools/op.go b/pkg/common/tools/op.go deleted file mode 100644 index df901055a..000000000 --- a/pkg/common/tools/op.go +++ /dev/null @@ -1,13 +0,0 @@ -package tools - -import "context" - -func OperationID(ctx context.Context) string { - s, _ := ctx.Value("operationID").(string) - return s -} - -func OpUserID(ctx context.Context) string { - s, _ := ctx.Value("opUserID").(string) - return s -} diff --git a/pkg/common/tracelog/ctx.go b/pkg/common/tracelog/ctx.go index 98f241787..77a15da15 100644 --- a/pkg/common/tracelog/ctx.go +++ b/pkg/common/tracelog/ctx.go @@ -1,28 +1,20 @@ package tracelog import ( - "Open_IM/pkg/common/constant" "Open_IM/pkg/utils" "context" "github.com/sirupsen/logrus" - "google.golang.org/grpc/status" "runtime" "strings" //"errors" "fmt" "github.com/gin-gonic/gin" - "net/http" ) const TraceLogKey = "tracelog" func NewCtx(c *gin.Context, api string) context.Context { - req := &ApiInfo{ApiName: api, GinCtx: c, Funcs: &[]FuncInfo{}} - return context.WithValue(c, TraceLogKey, req) -} - -func NewCtx1(c *gin.Context, api string) context.Context { req := &ApiInfo{ApiName: api, GinCtx: c, OperationID: c.GetHeader("operationID"), Funcs: &[]FuncInfo{}} return context.WithValue(c, TraceLogKey, req) } @@ -42,77 +34,11 @@ func GetOperationID(ctx context.Context) string { return ctx.Value(TraceLogKey).(*ApiInfo).OperationID } -//func ShowLog(ctx context.Context) { -// t := ctx.Value(TraceLogKey).(*ApiInfo) -// if ctx.Value(TraceLogKey).(*ApiInfo).GinCtx != nil { -// log.Info(t.OperationID, "api: ", t.ApiName) -// } else { -// log.Info(t.OperationID, "rpc: ", t.ApiName) -// } -// for _, v := range *t.Funcs { -// if v.Err != nil { -// log.Error(t.OperationID, "func: ", v.FuncName, " args: ", v.Args, v.Err.Error()) -// } else { -// switch v.LogLevel { -// case logrus.InfoLevel: -// log.Info(t.OperationID, "func: ", v.FuncName, " args: ", v.Args) -// case logrus.DebugLevel: -// log.Debug(t.OperationID, "func: ", v.FuncName, " args: ", v.Args) -// case logrus.WarnLevel: -// log.Debug(t.OperationID, "func: ", v.FuncName, " args: ", v.Args) -// } -// } -// } -//} - -func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) { - SetCtxInfo(ctx, funcName, err, args) - e := Unwrap(err) - switch t := e.(type) { - case *constant.ErrInfo: - ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, baseResp{ErrCode: t.ErrCode, ErrMsg: t.ErrMsg, ErrDtl: t.DetailErrMsg}) - //ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": t.ErrCode, "errMsg": t.ErrMsg, "errDtl": t.DetailErrMsg}) - return - default: - s, ok := status.FromError(e) - if !ok { - ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, &baseResp{ErrCode: constant.ErrDefaultOther.ErrCode, ErrMsg: err.Error(), ErrDtl: fmt.Sprintf("%+v", err)}) - //ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": constant.ErrDefaultOther.ErrCode, "errMsg": err.Error(), "errDtl": fmt.Sprintf("%+v", err)}) - return - } - var details []string - if err != e { - details = append(details, fmt.Sprintf("%+v", err)) - } - for _, s := range s.Details() { - details = append(details, fmt.Sprintf("%+v", s)) - } - ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, &baseResp{ErrCode: int32(s.Code()), ErrMsg: s.Message(), ErrDtl: strings.Join(details, "\n")}) - //ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": s.Code(), "errMsg": s.Message(), "errDtl": strings.Join(details, "\n")}) - return - } -} - -type baseResp struct { - ErrCode int32 `json:"errCode"` - ErrMsg string `json:"errMsg"` - ErrDtl string `json:"errDtl"` - Data interface{} `json:"data"` +func GetOpUserID(ctx context.Context) string { + s, _ := ctx.Value("opUserID").(string) + return s } -//func WriteErrorResponse(ctx context.Context, funcName string, err error, args ...interface{}) { -// SetCtxInfo(ctx, funcName, err, args) -// e := new(constant.ErrInfo) -// switch { -// case errors.As(err, &e): -// ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": e.ErrCode, "errMsg": e.ErrMsg}) -// return -// default: -// ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": constant.ErrDefaultOther.ErrCode, "errMsg": constant.ErrDefaultOther.ErrMsg, "errDtl": err.Error()}) -// return -// } -//} - func Unwrap(err error) error { for err != nil { unwrap, ok := err.(interface { @@ -211,11 +137,6 @@ func SetRpcRespInfo(ctx context.Context, funcName string, resp string) { *t.Funcs = append(*t.Funcs, funcInfo) } -func SetSuccess(ctx context.Context, funcName string, data interface{}) { - SetCtxInfo(ctx, funcName, nil, "data", data) - ctx.Value(TraceLogKey).(*ApiInfo).GinCtx.JSON(http.StatusOK, gin.H{"errCode": 0, "errMsg": "", "errDtl": "", "data": data}) -} - func argsHandle(args []interface{}, fields map[string]interface{}) { for i := 0; i < len(args); i += 2 { if i+1 < len(args) { diff --git a/internal/utils/convert.go b/pkg/utils/convert.go similarity index 99% rename from internal/utils/convert.go rename to pkg/utils/convert.go index 1660219ae..5ed75c7a0 100644 --- a/internal/utils/convert.go +++ b/pkg/utils/convert.go @@ -3,7 +3,6 @@ package utils import ( "Open_IM/pkg/common/db/relation" sdk "Open_IM/pkg/proto/sdk_ws" - utils2 "Open_IM/pkg/utils" utils "github.com/OpenIMSDK/open_utils" "time" ) diff --git a/internal/utils/cors_middleware_test.go b/pkg/utils/cors_middleware_test.go similarity index 97% rename from internal/utils/cors_middleware_test.go rename to pkg/utils/cors_middleware_test.go index 248cc1ca0..0abfe3f3a 100644 --- a/internal/utils/cors_middleware_test.go +++ b/pkg/utils/cors_middleware_test.go @@ -1,7 +1,6 @@ package utils import ( - "Open_IM/pkg/utils" "net/http" "net/http/httptest" "testing" @@ -36,7 +35,7 @@ func performRequestWithHeaders(r http.Handler, method, origin string, header htt func newTestRouter() *gin.Engine { router := gin.New() - router.Use(utils.CorsHandler()) + router.Use(CorsHandler()) router.GET("/", func(c *gin.Context) { c.String(http.StatusOK, "get") }) diff --git a/internal/utils/id.go b/pkg/utils/id.go similarity index 100% rename from internal/utils/id.go rename to pkg/utils/id.go diff --git a/internal/utils/id_test.go b/pkg/utils/id_test.go similarity index 100% rename from internal/utils/id_test.go rename to pkg/utils/id_test.go diff --git a/internal/utils/image_test.go b/pkg/utils/image_test.go similarity index 53% rename from internal/utils/image_test.go rename to pkg/utils/image_test.go index ab328fbc4..f28cfc89d 100644 --- a/internal/utils/image_test.go +++ b/pkg/utils/image_test.go @@ -1,7 +1,6 @@ package utils import ( - "Open_IM/pkg/utils" "path/filepath" "runtime" "testing" @@ -17,12 +16,12 @@ var ( func Test_GenSmallImage(t *testing.T) { println(Root) - err := utils.GenSmallImage(Root+"/docs/open-im-logo.png", Root+"/out-test/open-im-logo-test.png") + err := GenSmallImage(Root+"/docs/open-im-logo.png", Root+"/out-test/open-im-logo-test.png") assert.Nil(t, err) - err = utils.GenSmallImage(Root+"/docs/open-im-logo.png", "out-test/open-im-logo-test.png") + err = GenSmallImage(Root+"/docs/open-im-logo.png", "out-test/open-im-logo-test.png") assert.Nil(t, err) - err = utils.GenSmallImage(Root+"/docs/Architecture.jpg", "out-test/Architecture-test.jpg") + err = GenSmallImage(Root+"/docs/Architecture.jpg", "out-test/Architecture-test.jpg") assert.Nil(t, err) } diff --git a/internal/utils/jwt_token_test.go b/pkg/utils/jwt_token_test.go similarity index 100% rename from internal/utils/jwt_token_test.go rename to pkg/utils/jwt_token_test.go diff --git a/internal/utils/local_cache.go b/pkg/utils/local_cache.go similarity index 94% rename from internal/utils/local_cache.go rename to pkg/utils/local_cache.go index 551563a73..6fc35a79e 100644 --- a/internal/utils/local_cache.go +++ b/pkg/utils/local_cache.go @@ -6,7 +6,6 @@ import ( "Open_IM/pkg/common/log" "Open_IM/pkg/getcdv3" pbCache "Open_IM/pkg/proto/cache" - "Open_IM/pkg/utils" "context" "errors" "sync" @@ -27,7 +26,7 @@ func GetGroupMemberUserIDList(ctx context.Context, groupID string, operationID s defer CacheGroupMtx.Unlock() delete(CacheGroupMemberUserIDList, groupID) log.Error(operationID, "GetGroupMemberUserIDListHashFromRemote failed ", err.Error(), groupID) - return nil, utils.Wrap(err, groupID) + return nil, Wrap(err, groupID) } CacheGroupMtx.Lock() @@ -48,7 +47,7 @@ func GetGroupMemberUserIDList(ctx context.Context, groupID string, operationID s memberUserIDListRemote, err := GetGroupMemberUserIDListFromRemote(groupID, operationID) if err != nil { log.Error(operationID, "GetGroupMemberUserIDListFromRemote failed ", err.Error(), groupID) - return nil, utils.Wrap(err, groupID) + return nil, Wrap(err, groupID) } CacheGroupMemberUserIDList[groupID] = &GroupMemberUserIDListHash{MemberListHash: groupHashRemote, UserIDList: memberUserIDListRemote} return memberUserIDListRemote, nil @@ -68,7 +67,7 @@ func GetGroupMemberUserIDListFromRemote(groupID string, operationID string) ([]s cacheResp, err := client.GetGroupMemberIDListFromCache(context.Background(), getGroupMemberIDListFromCacheReq) if err != nil { log.NewError(operationID, "GetGroupMemberIDListFromCache rpc call failed ", err.Error()) - return nil, utils.Wrap(err, "GetGroupMemberIDListFromCache rpc call failed") + return nil, Wrap(err, "GetGroupMemberIDListFromCache rpc call failed") } if cacheResp.CommonResp.ErrCode != 0 { errMsg := operationID + "GetGroupMemberIDListFromCache rpc logic call failed " + cacheResp.CommonResp.ErrMsg diff --git a/internal/utils/md5_test.go b/pkg/utils/md5_test.go similarity index 72% rename from internal/utils/md5_test.go rename to pkg/utils/md5_test.go index 4db7bd854..63eec8077 100644 --- a/internal/utils/md5_test.go +++ b/pkg/utils/md5_test.go @@ -1,16 +1,15 @@ package utils import ( - "Open_IM/pkg/utils" "testing" "github.com/stretchr/testify/assert" ) func Test_Md5(t *testing.T) { - result := utils.Md5("go") + result := Md5("go") assert.Equal(t, result, "34d1f91fb2e514b8576fab1a75a89a6b") - result2 := utils.Md5("go") + result2 := Md5("go") assert.Equal(t, result, result2) } diff --git a/internal/utils/platform_number_id_to_name_test.go b/pkg/utils/platform_number_id_to_name_test.go similarity index 100% rename from internal/utils/platform_number_id_to_name_test.go rename to pkg/utils/platform_number_id_to_name_test.go diff --git a/pkg/tools/retry/retry.go b/pkg/utils/retry/retry.go similarity index 100% rename from pkg/tools/retry/retry.go rename to pkg/utils/retry/retry.go diff --git a/pkg/tools/retry/stratey.go b/pkg/utils/retry/stratey.go similarity index 100% rename from pkg/tools/retry/stratey.go rename to pkg/utils/retry/stratey.go diff --git a/pkg/tools/splitter/tools.go b/pkg/utils/splitter/tools.go similarity index 100% rename from pkg/tools/splitter/tools.go rename to pkg/utils/splitter/tools.go diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 92db70379..de5e0eb5f 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -8,6 +8,7 @@ import ( "github.com/jinzhu/copier" "github.com/pkg/errors" "math/rand" + "reflect" "runtime" "strconv" "strings" @@ -166,6 +167,7 @@ func Map2Pb(m map[string]string) (pb proto.Message, err error) { } return pb, nil } + func Pb2Map(pb proto.Message) (map[string]interface{}, error) { _buffer := bytes.Buffer{} jsonbMarshaller := &jsonpb.Marshaler{ @@ -179,3 +181,44 @@ func Pb2Map(pb proto.Message) (map[string]interface{}, error) { err := json.Unmarshal(jsonCnt, &out) return out, err } + +func JsonDataList(resp interface{}) []map[string]interface{} { + var list []proto.Message + if reflect.TypeOf(resp).Kind() == reflect.Slice { + s := reflect.ValueOf(resp) + for i := 0; i < s.Len(); i++ { + ele := s.Index(i) + list = append(list, ele.Interface().(proto.Message)) + } + } + + result := make([]map[string]interface{}, 0) + for _, v := range list { + m := ProtoToMap(v, false) + result = append(result, m) + } + return result +} + +func JsonDataOne(pb proto.Message) map[string]interface{} { + return ProtoToMap(pb, false) +} + +func ProtoToMap(pb proto.Message, idFix bool) map[string]interface{} { + marshaler := jsonpb.Marshaler{ + OrigName: true, + EnumsAsInts: false, + EmitDefaults: false, + } + + s, _ := marshaler.MarshalToString(pb) + out := make(map[string]interface{}) + json.Unmarshal([]byte(s), &out) + if idFix { + if _, ok := out["id"]; ok { + out["_id"] = out["id"] + delete(out, "id") + } + } + return out +}