From d06dc3e4b552e0aa49cde6839e375b9590f9cab2 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Thu, 12 Jan 2023 16:17:52 +0800 Subject: [PATCH] 1 --- pkg/common/middleware/rpc.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/common/middleware/rpc.go b/pkg/common/middleware/rpc.go index cda1c8f00..f8f2bcf4a 100644 --- a/pkg/common/middleware/rpc.go +++ b/pkg/common/middleware/rpc.go @@ -4,6 +4,7 @@ import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/log" "Open_IM/pkg/common/trace_log" + "Open_IM/pkg/utils" "context" "fmt" "google.golang.org/grpc" @@ -66,19 +67,18 @@ func rpcString(v interface{}) string { return fmt.Sprintf("%+v", v) } -//func RpcClientInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) (err error) { -// //if cc == nil { -// // return utils.Wrap(constant.ErrRpcConn, "") -// //} -// operationID, ok := ctx.Value("operationID").(string) -// if !ok { -// return utils.Wrap(constant.ErrArgs, "ctx missing operationID") -// } -// opUserID, ok := ctx.Value("opUserID").(string) -// if !ok { -// return utils.Wrap(constant.ErrArgs, "ctx missing opUserID") -// } -// md := metadata.Pairs("operationID", operationID, "opUserID", opUserID) -// return invoker(metadata.NewOutgoingContext(ctx, md), method, req, reply, cc, opts...) -//} -// +func RpcClientInterceptor(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) (err error) { + //if cc == nil { + // return utils.Wrap(constant.ErrRpcConn, "") + //} + operationID, ok := ctx.Value("operationID").(string) + if !ok { + return utils.Wrap(constant.ErrArgs, "ctx missing operationID") + } + opUserID, ok := ctx.Value("opUserID").(string) + if !ok { + return utils.Wrap(constant.ErrArgs, "ctx missing opUserID") + } + md := metadata.Pairs("operationID", operationID, "opUserID", opUserID) + return invoker(metadata.NewOutgoingContext(ctx, md), method, req, reply, cc, opts...) +}