test-errcode
withchao 2 years ago
parent 35c0e8303c
commit d142988390

@ -12,8 +12,6 @@ import (
rpc "Open_IM/pkg/proto/group"
"Open_IM/pkg/utils"
"context"
"google.golang.org/grpc/metadata"
"github.com/golang/protobuf/ptypes/wrappers"
"google.golang.org/grpc"
@ -1256,48 +1254,58 @@ func SetGroupMemberInfo(c *gin.Context) {
}
func GetGroupAbstractInfo(c *gin.Context) {
var (
req api.GetGroupAbstractInfoReq
resp api.GetGroupAbstractInfoResp
)
nCtx := trace_log.NewCtx(c, utils.GetSelfFuncName())
if err := c.BindJSON(&req); err != nil {
log.NewError("0", "BindJSON failed ", err.Error())
c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
return
}
ok, opUserID, errInfo := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
if !ok {
errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, req.OperationID)
if etcdConn == nil {
errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
log.NewError(req.OperationID, errMsg)
c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
return
}
client := rpc.NewGroupClient(etcdConn)
md := metadata.Pairs("operationID", req.OperationID, "opUserID", opUserID)
respPb, err := client.GetGroupAbstractInfo(metadata.NewOutgoingContext(c, md), &rpc.GetGroupAbstractInfoReq{
GroupID: req.GroupID,
OpUserID: opUserID,
OperationID: req.OperationID,
})
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", respPb.String())
if err != nil {
//log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", err.Error())
//c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
trace_log.WriteErrorResponse(nCtx, "GetGroupAbstractInfo", utils.Wrap(err, ""))
return
}
resp.GroupMemberNumber = respPb.GroupMemberNumber
resp.GroupMemberListHash = respPb.GroupMemberListHash
log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
c.JSON(http.StatusOK, resp)
return
type GetGroupAbstractInfoReq struct {
//OperationID string `json:"operationID"`
GroupID string `json:"groupID"`
}
type GetGroupAbstractInfoResp struct {
GroupMemberNumber int32 `json:"groupMemberNumber"`
GroupMemberListHash uint64 `json:"groupMemberListHash"`
}
common.ApiToRpc(c, &api.GetGroupAbstractInfoReq{}, &GetGroupAbstractInfoResp{}, config.Config.RpcRegisterName.OpenImGroupName, rpc.NewGroupClient, utils.GetSelfFuncName(), token_verify.ParseUserIDFromToken)
//var (
//req api.GetGroupAbstractInfoReq
//resp api.GetGroupAbstractInfoResp
//)
//nCtx := trace_log.NewCtx(c, utils.GetSelfFuncName())
//if err := c.BindJSON(&req); err != nil {
// log.NewError("0", "BindJSON failed ", err.Error())
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 400, "errMsg": err.Error()})
// return
//}
//ok, opUserID, errInfo := token_verify.GetUserIDFromToken(c.Request.Header.Get("token"), req.OperationID)
//if !ok {
// errMsg := req.OperationID + " " + "GetUserIDFromToken failed " + errInfo + " token:" + c.Request.Header.Get("token")
// log.NewError(req.OperationID, errMsg)
// c.JSON(http.StatusBadRequest, gin.H{"errCode": 500, "errMsg": errMsg})
// return
//}
//
//etcdConn := getcdv3.GetDefaultConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImGroupName, req.OperationID)
//if etcdConn == nil {
// errMsg := req.OperationID + "getcdv3.GetDefaultConn == nil"
// log.NewError(req.OperationID, errMsg)
// c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": errMsg})
// return
//}
//client := rpc.NewGroupClient(etcdConn)
//md := metadata.Pairs("operationID", req.OperationID, "opUserID", opUserID)
//respPb, err := client.GetGroupAbstractInfo(metadata.NewOutgoingContext(c, md), &rpc.GetGroupAbstractInfoReq{
// GroupID: req.GroupID,
// OpUserID: opUserID,
// OperationID: req.OperationID,
//})
//log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api args ", respPb.String())
//if err != nil {
// //log.NewError(req.OperationID, utils.GetSelfFuncName(), " failed ", err.Error())
// //c.JSON(http.StatusInternalServerError, gin.H{"errCode": 500, "errMsg": err.Error()})
// trace_log.WriteErrorResponse(nCtx, "GetGroupAbstractInfo", utils.Wrap(err, ""))
// return
//}
//resp.GroupMemberNumber = respPb.GroupMemberNumber
//resp.GroupMemberListHash = respPb.GroupMemberListHash
//log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " api return ", resp)
//c.JSON(http.StatusOK, resp)
//return
}

@ -9,7 +9,7 @@ import (
"reflect"
)
func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, fn interface{}, rpcFuncName string, tokenFunc func(token string, operationID string) (string, error)) {
func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcClientFunc interface{}, rpcFuncName string, tokenFunc func(token string, operationID string) (string, error)) {
operationID := c.GetHeader("operationID")
nCtx := trace_log.NewCtx(c, rpcFuncName)
defer trace_log.ShowLog(nCtx)
@ -24,7 +24,7 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, fn in
trace_log.WriteErrorResponse(nCtx, "GetDefaultConn", err)
return
}
rpc := reflect.ValueOf(fn).Call([]reflect.Value{
rpc := reflect.ValueOf(rpcClientFunc).Call([]reflect.Value{
reflect.ValueOf(etcdConn),
})[0].MethodByName(rpcFuncName) // rpc func
rpcReqPtr := reflect.New(rpc.Type().In(1).Elem()) // *req参数

Loading…
Cancel
Save