Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
withchao committed Jul 6, 2023
1 parent 724e89d commit 634d5c9
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions pkg/common/mw/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,18 @@ package mw
import (
"context"
"github.com/OpenIMSDK/Open-IM-Server/pkg/common/log"
"github.com/OpenIMSDK/Open-IM-Server/pkg/errs"
"github.com/OpenIMSDK/chat/pkg/common/constant"
"google.golang.org/grpc"
"strconv"
)

func AddUserType() grpc.DialOption {
return grpc.WithChainUnaryInterceptor(func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
log.ZInfo(ctx, "add user type", "method", method)
if arr, _ := ctx.Value(constant.RpcOpUserType).([]string); len(arr) > 0 {
userType, err := strconv.Atoi(arr[0])
if err != nil {
return errs.ErrInternalServer.Wrap("user type is not int")
}
log.ZInfo(ctx, "add user type", "method", method, "userType", userType)
log.ZInfo(ctx, "add user type", "method", method, "userType", arr)
headers, _ := ctx.Value(constant.RpcCustomHeader).([]string)
ctx = context.WithValue(ctx, constant.RpcCustomHeader, append(headers, constant.RpcOpUserType))
ctx = context.WithValue(ctx, constant.RpcOpUserType, userType)
ctx = context.WithValue(ctx, constant.RpcOpUserType, arr)
}
return invoker(ctx, method, req, reply, cc, opts...)
})
Expand Down

0 comments on commit 634d5c9

Please sign in to comment.