From 679441fc3077b60c39a102bb1260a0df03bbe6aa Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Fri, 23 Dec 2022 17:53:31 +0800 Subject: [PATCH] update --- pkg/interceptor/interceptor.go | 28 ++++++++++++++-------------- test/tcp_conn/main.go | 2 +- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/pkg/interceptor/interceptor.go b/pkg/interceptor/interceptor.go index 92dff05..76b69d8 100644 --- a/pkg/interceptor/interceptor.go +++ b/pkg/interceptor/interceptor.go @@ -21,16 +21,17 @@ func NewInterceptor(name string, urlWhitelist map[string]int) grpc.UnaryServerIn defer gerrors.LogPanic(name, ctx, req, info, &err) md, _ := metadata.FromIncomingContext(ctx) - resp, err = handleMasterAuth(ctx, req, info, handler) - //logger.Logger.Debug(name, zap.Any("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req), - // zap.Any("resp", resp), zap.Error(err)) - //s, _ := status.FromError(err) - //if s.Code() != 0 && s.Code() < 1000 { - // md, _ := metadata.FromIncomingContext(ctx) - // logger.Logger.Error(name, zap.String("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req), - // zap.Any("resp", resp), zap.Error(err), zap.String("stack", gerrors.GetErrorStack(s))) - //} + err = handleMasterAuth(ctx, req, info, handler) + logger.Logger.Debug(name, zap.Any("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req), + zap.Any("resp", resp), zap.Error(err)) + + s, _ := status.FromError(err) + if s.Code() != 0 && s.Code() < 1000 { + md, _ := metadata.FromIncomingContext(ctx) + logger.Logger.Error(name, zap.String("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req), + zap.Any("resp", resp), zap.Error(err), zap.String("stack", gerrors.GetErrorStack(s))) + } if err != nil { return } @@ -38,8 +39,7 @@ func NewInterceptor(name string, urlWhitelist map[string]int) grpc.UnaryServerIn resp, err = handleWithAuth(ctx, req, info, handler, urlWhitelist) logger.Logger.Debug(name, zap.Any("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req), zap.Any("resp", resp), zap.Error(err)) - - s, _ := status.FromError(err) + s, _ = status.FromError(err) if s.Code() != 0 && s.Code() < 1000 { md, _ := metadata.FromIncomingContext(ctx) logger.Logger.Error(name, zap.String("method", info.FullMethod), zap.Any("md", md), zap.Any("req", req), @@ -78,15 +78,15 @@ func handleWithAuth(ctx context.Context, req interface{}, info *grpc.UnaryServer } // handleMasterAuth 处理站长权限 -func handleMasterAuth(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) { +func handleMasterAuth(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) error { serverName := strings.Split(info.FullMethod, "/")[1] if !strings.HasSuffix(serverName, "Int") { masterId, err := grpclib.GetCtxMasterId(ctx) _, err = rpc.GetBusinessIntClient().MasterAuth(ctx, &pb.MasterAuthReq{MasterId: masterId}) if err != nil { - return nil, err + return err } } - return handler(ctx, req) + return nil } diff --git a/test/tcp_conn/main.go b/test/tcp_conn/main.go index 2173a39..a35ae5a 100644 --- a/test/tcp_conn/main.go +++ b/test/tcp_conn/main.go @@ -88,7 +88,7 @@ func (c *TcpClient) SignIn() { signIn := pb.SignInInput{ UserId: c.UserId, DeviceId: c.DeviceId, - Token: "WAOLJWZLZNTJRSOVGCLPZHQYDIIPMUFAYKYESISY", + Token: "AIXWNMSQRYTVBOFIICDRZQYXPRHFUNTIXHVTSNVN", } c.Output(pb.PackageType_PT_SIGN_IN, time.Now().UnixNano(), &signIn) }