|
|
@ -2,24 +2,32 @@ package middleware
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
"Open_IM/pkg/common/constant"
|
|
|
|
|
|
|
|
"Open_IM/pkg/common/log"
|
|
|
|
"Open_IM/pkg/common/trace_log"
|
|
|
|
"Open_IM/pkg/common/trace_log"
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
"Open_IM/pkg/utils"
|
|
|
|
"context"
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/metadata"
|
|
|
|
"google.golang.org/grpc/metadata"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
"google.golang.org/grpc/status"
|
|
|
|
"google.golang.org/protobuf/types/known/wrapperspb"
|
|
|
|
"google.golang.org/protobuf/types/known/wrapperspb"
|
|
|
|
"path"
|
|
|
|
"path"
|
|
|
|
|
|
|
|
"runtime/debug"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func RpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
|
|
|
func RpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
|
|
|
|
|
|
|
var operationID string
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
|
|
|
|
log.NewError(operationID, info.FullMethod, "type:", fmt.Sprintf("%T", r), "panic:", r, "stack:", string(debug.Stack()))
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}()
|
|
|
|
funcName := path.Base(info.FullMethod)
|
|
|
|
funcName := path.Base(info.FullMethod)
|
|
|
|
md, ok := metadata.FromIncomingContext(ctx)
|
|
|
|
md, ok := metadata.FromIncomingContext(ctx)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
return nil, status.New(codes.InvalidArgument, "missing metadata").Err()
|
|
|
|
return nil, status.New(codes.InvalidArgument, "missing metadata").Err()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var operationID string
|
|
|
|
|
|
|
|
if opts := md.Get("operationID"); len(opts) != 1 || opts[0] == "" {
|
|
|
|
if opts := md.Get("operationID"); len(opts) != 1 || opts[0] == "" {
|
|
|
|
return nil, status.New(codes.InvalidArgument, "operationID error").Err()
|
|
|
|
return nil, status.New(codes.InvalidArgument, "operationID error").Err()
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|