mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 09:05:59 +08:00
errcode
This commit is contained in:
@@ -16,16 +16,16 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcCl
|
||||
rpcName = utils2.GetFuncName(1)
|
||||
}
|
||||
logFuncName := fmt.Sprintf("[ApiToRpc: %s]%s", utils2.GetFuncName(1), rpcFuncName)
|
||||
ctx := trace_log.NewCtx1(c, rpcFuncName)
|
||||
ctx := tracelog.NewCtx1(c, rpcFuncName)
|
||||
defer log.ShowLog(ctx)
|
||||
if err := c.BindJSON(apiReq); err != nil {
|
||||
trace_log.WriteErrorResponse(ctx, "BindJSON", err)
|
||||
tracelog.WriteErrorResponse(ctx, "BindJSON", err)
|
||||
return
|
||||
}
|
||||
trace_log.SetCtxInfo(ctx, logFuncName, nil, "apiReq", apiReq)
|
||||
tracelog.SetCtxInfo(ctx, logFuncName, nil, "apiReq", apiReq)
|
||||
etcdConn, err := getcdv3.GetConn(ctx, rpcName)
|
||||
if err != nil {
|
||||
trace_log.WriteErrorResponse(ctx, "GetConn", err)
|
||||
tracelog.WriteErrorResponse(ctx, "GetConn", err)
|
||||
return
|
||||
}
|
||||
rpcClient := reflect.ValueOf(rpcClientFunc).Call([]reflect.Value{
|
||||
@@ -33,22 +33,22 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcCl
|
||||
})[0].MethodByName(rpcFuncName) // rpcClient func
|
||||
rpcReqPtr := reflect.New(rpcClient.Type().In(1).Elem()) // *req
|
||||
CopyAny(apiReq, rpcReqPtr.Interface())
|
||||
trace_log.SetCtxInfo(ctx, logFuncName, nil, "opUserID", c.GetString("opUserID"), "callRpcReq", rpcString(rpcReqPtr.Elem().Interface()))
|
||||
tracelog.SetCtxInfo(ctx, logFuncName, nil, "opUserID", c.GetString("opUserID"), "callRpcReq", rpcString(rpcReqPtr.Elem().Interface()))
|
||||
respArr := rpcClient.Call([]reflect.Value{
|
||||
reflect.ValueOf(context.Context(c)), // context.Context (ctx operationID. opUserID)
|
||||
rpcReqPtr, // rpcClient apiReq
|
||||
}) // respArr => (apiResp, error)
|
||||
if !respArr[1].IsNil() { // rpcClient err != nil
|
||||
err := respArr[1].Interface().(error)
|
||||
trace_log.WriteErrorResponse(ctx, rpcFuncName, err, "callRpcResp", "error")
|
||||
tracelog.WriteErrorResponse(ctx, rpcFuncName, err, "callRpcResp", "error")
|
||||
return
|
||||
}
|
||||
rpcResp := respArr[0].Elem()
|
||||
trace_log.SetCtxInfo(ctx, rpcFuncName, nil, "callRpcResp", rpcString(rpcResp.Interface()))
|
||||
tracelog.SetCtxInfo(ctx, rpcFuncName, nil, "callRpcResp", rpcString(rpcResp.Interface()))
|
||||
if apiResp != nil {
|
||||
CopyAny(rpcResp.Interface(), apiResp)
|
||||
}
|
||||
trace_log.SetSuccess(ctx, rpcFuncName, apiResp)
|
||||
tracelog.SetSuccess(ctx, rpcFuncName, apiResp)
|
||||
}
|
||||
|
||||
func rpcString(v interface{}) string {
|
||||
|
||||
Reference in New Issue
Block a user