mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-25 02:58:26 +08:00
1
This commit is contained in:
parent
be39542832
commit
f5fc429b34
@ -1,6 +1,7 @@
|
||||
package common
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/common/trace_log"
|
||||
"Open_IM/pkg/getcdv3"
|
||||
utils2 "Open_IM/pkg/utils"
|
||||
@ -11,7 +12,7 @@ import (
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcClientFunc 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) {
|
||||
logFuncName := fmt.Sprintf("[ApiToRpc: %s]%s", utils2.GetFuncName(1), rpcFuncName)
|
||||
operationID := c.GetHeader("operationID")
|
||||
nCtx := trace_log.NewCtx1(c, rpcFuncName, operationID)
|
||||
@ -30,23 +31,12 @@ func ApiToRpc(c *gin.Context, apiReq, apiResp interface{}, rpcName string, rpcCl
|
||||
reflect.ValueOf(etcdConn),
|
||||
})[0].MethodByName(rpcFuncName) // rpc func
|
||||
rpcReqPtr := reflect.New(rpc.Type().In(1).Elem()) // *req参数
|
||||
var opUserID string
|
||||
if tokenFunc != nil {
|
||||
var err error
|
||||
opUserID, err = tokenFunc(c.GetHeader("token"), operationID)
|
||||
if err != nil {
|
||||
trace_log.WriteErrorResponse(nCtx, "TokenFunc", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := utils.CopyStructFields(rpcReqPtr.Interface(), apiReq); err != nil {
|
||||
trace_log.WriteErrorResponse(nCtx, "CopyStructFields_RpcReq", err)
|
||||
return
|
||||
}
|
||||
trace_log.SetCtxInfo(nCtx, logFuncName, nil, "opUserID", opUserID, "callRpcReq", rpcString(rpcReqPtr.Elem().Interface()))
|
||||
//md := metadata.Pairs("operationID", operationID, "opUserID", opUserID)
|
||||
trace_log.SetCtxInfo(nCtx, logFuncName, nil, "opUserID", c.GetString("opUserID"), "callRpcReq", rpcString(rpcReqPtr.Elem().Interface()))
|
||||
respArr := rpc.Call([]reflect.Value{
|
||||
//reflect.ValueOf(metadata.NewOutgoingContext(c, md)), // context.Context
|
||||
reflect.ValueOf(context.Context(c)), // context.Context
|
||||
rpcReqPtr, // rpc apiReq
|
||||
}) // respArr => (apiResp, error)
|
||||
|
Loading…
x
Reference in New Issue
Block a user