From eb640157f2c5f277b7284ea6a47916e4c55e66e6 Mon Sep 17 00:00:00 2001 From: wenxu12345 <44203734@qq.com> Date: Tue, 28 Dec 2021 16:58:01 +0800 Subject: [PATCH] tidy code --- internal/api/auth/auth.go | 6 +++--- pkg/utils/utils.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/api/auth/auth.go b/internal/api/auth/auth.go index 5dde76778..4ab27e3f4 100644 --- a/internal/api/auth/auth.go +++ b/internal/api/auth/auth.go @@ -7,6 +7,7 @@ import ( "Open_IM/pkg/grpc-etcdv3/getcdv3" rpc "Open_IM/pkg/proto/auth" open_im_sdk "Open_IM/pkg/proto/sdk_ws" + "Open_IM/pkg/utils" "context" "github.com/gin-gonic/gin" "github.com/jinzhu/copier" @@ -28,16 +29,15 @@ func UserRegister(c *gin.Context) { return } req := &rpc.UserRegisterReq{UserInfo: &open_im_sdk.UserInfo{}} - //utils.CopyStructFields(*req.UserInfo, params) + utils.CopyStructFields(*req.UserInfo, params) copier.Copy(req.UserInfo, ¶ms) req.OperationID = params.OperationID log.NewInfo(req.OperationID, "UserRegister args ", req.String()) etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImAuthName) client := rpc.NewAuthClient(etcdConn) reply, err := client.UserRegister(context.Background(), req) - if err != nil || reply.CommonResp.ErrCode != 0 { - log.NewError("0", "UserRegister failed ", err, reply.CommonResp.ErrCode) + log.NewError(req.OperationID, "UserRegister failed ", err, reply.CommonResp.ErrCode) c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()}) return } diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 3d4a595fe..d5dc0254a 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -8,7 +8,7 @@ import ( // copy a by b b->a func CopyStructFields(a interface{}, b interface{}, fields ...string) (err error) { - return copier.Copy(&a, &b) + return copier.Copy(a, b) at := reflect.TypeOf(a) av := reflect.ValueOf(a)