From aae6874928deb939c3b6881b12e51baa81f850f1 Mon Sep 17 00:00:00 2001 From: Gordon <1432970085@qq.com> Date: Mon, 15 Nov 2021 16:10:56 +0800 Subject: [PATCH] null pointer fix --- internal/api/friend/add_friend.go | 6 +++++- internal/api/manage/management_user.go | 6 +++++- internal/rpc/user/management_user.go | 6 ++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/internal/api/friend/add_friend.go b/internal/api/friend/add_friend.go index 81faa29fb..8753a2350 100644 --- a/internal/api/friend/add_friend.go +++ b/internal/api/friend/add_friend.go @@ -48,8 +48,12 @@ func ImportFriend(c *gin.Context) { c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "cImportFriend failed " + err.Error()}) return } + failedUidList := make([]string, 0) + for _, v := range RpcResp.FailedUidList { + failedUidList = append(failedUidList, v) + } log.NewDebug(req.OperationID, "rpc importFriend success", RpcResp.CommonResp.ErrorMsg, RpcResp.CommonResp.ErrorCode, RpcResp.FailedUidList) - c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "failedUidList": RpcResp.FailedUidList}) + c.JSON(http.StatusOK, gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "failedUidList": failedUidList}) } func AddFriend(c *gin.Context) { diff --git a/internal/api/manage/management_user.go b/internal/api/manage/management_user.go index 79436cf04..dce66a41e 100644 --- a/internal/api/manage/management_user.go +++ b/internal/api/manage/management_user.go @@ -43,10 +43,14 @@ func DeleteUser(c *gin.Context) { } RpcResp, err := client.DeleteUsers(context.Background(), req) if err != nil { - + log.NewError(req.OperationID, "call delete users rpc server failed", err.Error()) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": "call delete users rpc server failed"}) return } + failedUidList := make([]string, 0) + for _, v := range RpcResp.FailedUidList { + failedUidList = append(failedUidList, v) + } log.InfoByKv("call delete user rpc server is success", params.OperationID, "resp args", RpcResp.String()) resp := gin.H{"errCode": RpcResp.CommonResp.ErrorCode, "errMsg": RpcResp.CommonResp.ErrorMsg, "failedUidList": RpcResp.FailedUidList} c.JSON(http.StatusOK, resp) diff --git a/internal/rpc/user/management_user.go b/internal/rpc/user/management_user.go index f9d5b75a1..524b98e71 100644 --- a/internal/rpc/user/management_user.go +++ b/internal/rpc/user/management_user.go @@ -18,6 +18,7 @@ import ( func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) (*pbUser.DeleteUsersResp, error) { log.InfoByKv("rpc DeleteUsers arrived server", req.OperationID, "args", req.String()) var resp pbUser.DeleteUsersResp + var common pbUser.CommonResp c, err := utils.ParseToken(req.Token) if err != nil { log.ErrorByKv("parse token failed", req.OperationID, "err", err.Error()) @@ -30,11 +31,12 @@ func (s *userServer) DeleteUsers(_ context.Context, req *pbUser.DeleteUsersReq) for _, uid := range req.DeleteUidList { err = im_mysql_model.UserDelete(uid) if err != nil { - resp.CommonResp.ErrorCode = 201 - resp.CommonResp.ErrorMsg = "some uid deleted failed" + common.ErrorCode = 201 + common.ErrorMsg = "some uid deleted failed" resp.FailedUidList = append(resp.FailedUidList, uid) } } + resp.CommonResp = &common return &resp, nil }