提交 1b11cd57 编写于 作者: W wenxu12345

Refactor code

上级 f3a98577
......@@ -10,8 +10,10 @@ import (
open_im_sdk "Open_IM/pkg/proto/sdk_ws"
"Open_IM/pkg/utils"
"context"
"encoding/json"
"github.com/gin-gonic/gin"
"github.com/golang/protobuf/jsonpb"
"github.com/golang/protobuf/proto"
"net/http"
"strings"
)
......@@ -170,13 +172,31 @@ func GetGroupAllMemberList(c *gin.Context) {
if len(memberListResp.MemberList) > 0 {
s, err := jsm.MarshalToString(memberListResp.MemberList[0])
//{"GroupID":"7836e478bc43ce1d3b8889cac983f59b","UserID":"openIM001","roleLevel":1,"JoinTime":"0","NickName":"","FaceUrl":"https://oss.com.cn/head","AppMangerLevel":0,"JoinSource":0,"OperatorUserID":"","Ex":"xxx"}
log.NewDebug(req.OperationID, "MarshalToString ", s, err)
m := ProtoToMap(memberListResp.MemberList[0], false)
log.NewDebug(req.OperationID, "mmm ", m)
memberListResp.Test = m
}
log.NewInfo(req.OperationID, "GetGroupAllMember api return ", memberListResp)
c.JSON(http.StatusOK, memberListResp)
}
func ProtoToMap(pb proto.Message, idFix bool) map[string]interface{} {
marshaler := jsonpb.Marshaler{}
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
}
func GetJoinedGroupList(c *gin.Context) {
params := api.GetJoinedGroupListReq{}
if err := c.BindJSON(&params); err != nil {
......
......@@ -64,12 +64,13 @@ type GetGroupMemberListResp struct {
}
type GetGroupAllMemberReq struct {
GroupID string `json:"groupID"`
OperationID string `json:"operationID"`
GroupID string `json:"groupID" binding:"required"`
OperationID string `json:"operationID" binding:"required"`
}
type GetGroupAllMemberResp struct {
CommResp
MemberList []*open_im_sdk.GroupMemberFullInfo `json:"data"`
Test map[string]interface{} `json:"data2"`
}
type CreateGroupReq struct {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册