From c4fca3b23d48682da91c391a0425f159f02707bb Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Wed, 29 Dec 2021 12:22:10 +0800 Subject: [PATCH] nil return modify --- internal/api/conversation/conversation.go | 18 ++++++++++----- internal/api/manage/management_user.go | 28 +++++++++++------------ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/internal/api/conversation/conversation.go b/internal/api/conversation/conversation.go index 38030279e..2a66be9dd 100644 --- a/internal/api/conversation/conversation.go +++ b/internal/api/conversation/conversation.go @@ -39,8 +39,10 @@ func GetAllConversationMessageOpt(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetAllConversationMsgOpt rpc failed, " + err.Error()}) return } - resp := api.GetAllConversationMessageOptResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}} - resp.ConversationOptResultList = RpcResp.ConversationOptResultList + resp := api.GetAllConversationMessageOptResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, ConversationOptResultList: RpcResp.ConversationOptResultList} + if len(RpcResp.ConversationOptResultList) == 0 { + resp.ConversationOptResultList = []*user.OptResult{} + } log.NewInfo(req.OperationID, "GetAllConversationMsgOpt api return: ", resp) c.JSON(http.StatusOK, resp) } @@ -69,8 +71,10 @@ func GetReceiveMessageOpt(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "GetReceiveMessageOpt rpc failed, " + err.Error()}) return } - resp := api.GetReceiveMessageOptResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}} - resp.ConversationOptResultList = RpcResp.ConversationOptResultList + resp := api.GetReceiveMessageOptResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, ConversationOptResultList: RpcResp.ConversationOptResultList} + if len(RpcResp.ConversationOptResultList) == 0 { + resp.ConversationOptResultList = []*user.OptResult{} + } log.NewInfo(req.OperationID, "GetReceiveMessageOpt api return: ", resp) c.JSON(http.StatusOK, resp) } @@ -99,8 +103,10 @@ func SetReceiveMessageOpt(c *gin.Context) { c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": "SetReceiveMessageOpt rpc failed, " + err.Error()}) return } - resp := api.SetReceiveMessageOptResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}} - resp.OptResultList = RpcResp.OptResultList + resp := api.SetReceiveMessageOptResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, OptResultList: RpcResp.OptResultList} + if len(RpcResp.OptResultList) == 0 { + resp.OptResultList = []*user.OptResult{} + } log.NewInfo(req.OperationID, "SetReceiveMessageOpt api return: ", resp) c.JSON(http.StatusOK, resp) } diff --git a/internal/api/manage/management_user.go b/internal/api/manage/management_user.go index 605bb5ddd..6ef6f678f 100644 --- a/internal/api/manage/management_user.go +++ b/internal/api/manage/management_user.go @@ -47,12 +47,10 @@ func DeleteUser(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete users rpc server failed"}) return } - failedUserIDList := make([]string, 0) - for _, v := range RpcResp.FailedUserIDList { - failedUserIDList = append(failedUserIDList, v) + resp := api.DeleteUsersResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, FailedUserIDList: RpcResp.FailedUserIDList} + if len(RpcResp.FailedUserIDList) == 0 { + resp.FailedUserIDList = []string{} } - resp := api.DeleteUsersResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}} - resp.FailedUserIDList = failedUserIDList log.NewInfo(req.OperationID, "DeleteUser api return", resp) c.JSON(http.StatusOK, resp) } @@ -80,12 +78,10 @@ func GetAllUsersUid(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call GetAllUsersUid users rpc server failed"}) return } - userIDList := make([]string, 0) - for _, v := range RpcResp.UserIDList { - userIDList = append(userIDList, v) + resp := api.GetAllUsersUidResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, UserIDList: RpcResp.UserIDList} + if len(RpcResp.UserIDList) == 0 { + resp.UserIDList = []string{} } - resp := api.GetAllUsersUidResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}} - resp.UserIDList = userIDList log.NewInfo(req.OperationID, "GetAllUsersUid api return", resp) c.JSON(http.StatusOK, resp) @@ -115,8 +111,10 @@ func AccountCheck(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call AccountCheck users rpc server failed"}) return } - resp := api.AccountCheckResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}} - resp.ResultList = RpcResp.ResultList + resp := api.AccountCheckResp{CommResp: api.CommResp{ErrCode: RpcResp.CommonResp.ErrCode, ErrMsg: RpcResp.CommonResp.ErrMsg}, ResultList: RpcResp.ResultList} + if len(RpcResp.ResultList) == 0 { + resp.ResultList = []*rpc.AccountCheckResp_SingleUserStatus{} + } log.NewInfo(req.OperationID, "AccountCheck api return", resp) c.JSON(http.StatusOK, resp) } @@ -172,8 +170,10 @@ func GetUsersOnlineStatus(c *gin.Context) { } respResult = append(respResult, temp) } - resp := api.GetUsersOnlineStatusResp{CommResp: api.CommResp{ErrCode: 0, ErrMsg: ""}} - resp.SuccessResult = respResult + resp := api.GetUsersOnlineStatusResp{CommResp: api.CommResp{ErrCode: 0, ErrMsg: ""}, SuccessResult: respResult} + if len(respResult) == 0 { + resp.SuccessResult = []*pbRelay.GetUsersOnlineStatusResp_SuccessResult{} + } log.NewInfo(req.OperationID, "GetUsersOnlineStatus api return", resp) c.JSON(http.StatusOK, resp)