|
|
@ -4,7 +4,6 @@ import (
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
"Open_IM/pkg/common/trace_log"
|
|
|
|
"Open_IM/pkg/common/trace_log"
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
@ -60,25 +59,26 @@ func RpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 rpcString(v interface{}) string {
|
|
|
|
func rpcString(v interface{}) string {
|
|
|
|
if s, ok := v.(interface{ String() string }); ok {
|
|
|
|
if s, ok := v.(interface{ String() string }); ok {
|
|
|
|
return s.String()
|
|
|
|
return s.String()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%+v", v)
|
|
|
|
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...)
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
//
|
|
|
|