msg update

This commit is contained in:
Gordon
2023-03-21 12:28:21 +08:00
parent 7eb28e7d0a
commit c036d27b36
40 changed files with 215 additions and 188 deletions
+1 -1
View File
@@ -153,7 +153,7 @@ func GinParseToken(rdb redis.UniversalClient) gin.HandlerFunc {
return
}
}
c.Set(constant.OpUserIDPlatformID, constant.PlatformNameToID(claims.Platform))
c.Set(constant.OpUserPlatform, claims.Platform)
c.Set(constant.OpUserID, claims.UID)
c.Next()
}
+4
View File
@@ -32,6 +32,10 @@ func rpcClientInterceptor(ctx context.Context, method string, req, resp interfac
if ok {
md.Append(constant.OpUserID, opUserID)
}
opUserIDPlatformID, ok := ctx.Value(constant.OpUserPlatform).(string)
if ok {
md.Append(constant.OpUserPlatform, opUserIDPlatformID)
}
err = invoker(metadata.NewOutgoingContext(ctx, md), method, req, resp, cc, opts...)
if err == nil {
log.ZInfo(ctx, "rpc client resp", "funcName", method, "resp", rpcString(resp))
+8 -11
View File
@@ -3,6 +3,7 @@ package mw
import (
"context"
"fmt"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/constant"
"math"
"runtime"
"runtime/debug"
@@ -20,9 +21,6 @@ import (
"google.golang.org/grpc/status"
)
const OperationID = "operationID"
const OpUserID = "opUserID"
func rpcString(v interface{}) string {
if s, ok := v.(interface{ String() string }); ok {
return s.String()
@@ -31,7 +29,6 @@ func rpcString(v interface{}) string {
}
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.ZError(ctx, "rpc panic", nil, "FullMethod", info.FullMethod, "type:", fmt.Sprintf("%T", r), "panic:", r)
@@ -59,17 +56,17 @@ func rpcServerInterceptor(ctx context.Context, req interface{}, info *grpc.Unary
if !ok {
return nil, status.New(codes.InvalidArgument, "missing metadata").Err()
}
if opts := md.Get(OperationID); len(opts) != 1 || opts[0] == "" {
if opts := md.Get(constant.OperationID); len(opts) != 1 || opts[0] == "" {
return nil, status.New(codes.InvalidArgument, "operationID error").Err()
} else {
operationID = opts[0]
ctx = context.WithValue(ctx, constant.OperationID, opts[0])
}
var opUserID string
if opts := md.Get(OpUserID); len(opts) == 1 {
opUserID = opts[0]
if opts := md.Get(constant.OpUserID); len(opts) == 1 {
ctx = context.WithValue(ctx, constant.OpUserID, opts[0])
}
if opts := md.Get(constant.OpUserPlatform); len(opts) == 1 {
ctx = context.WithValue(ctx, constant.OpUserPlatform, opts[0])
}
ctx = context.WithValue(ctx, OperationID, operationID)
ctx = context.WithValue(ctx, OpUserID, opUserID)
log.ZInfo(ctx, "rpc server req", "funcName", funcName, "req", rpcString(req))
resp, err = handler(ctx, req)
if err == nil {