From 3af7f2547c7c6ee0c7ecfc9b5f3bfb897284e318 Mon Sep 17 00:00:00 2001 From: DengBiao <2319963317@qq.com> Date: Fri, 16 Dec 2022 23:33:50 +0800 Subject: [PATCH] update auth --- internal/business/domain/user/service/auth.go | 1 + pkg/interceptor/interceptor.go | 13 ++++++++++--- test/tcp_conn/main.go | 5 +++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/internal/business/domain/user/service/auth.go b/internal/business/domain/user/service/auth.go index 6a01645..9385a39 100644 --- a/internal/business/domain/user/service/auth.go +++ b/internal/business/domain/user/service/auth.go @@ -123,5 +123,6 @@ func (*authService) AuthMaster(ctx context.Context, masterId string) error { if packageExpireTime < time.Now().Unix() { return gerrors.ErrMasterUnauthorized } + return nil } diff --git a/pkg/interceptor/interceptor.go b/pkg/interceptor/interceptor.go index 7500d5e..1b592b5 100644 --- a/pkg/interceptor/interceptor.go +++ b/pkg/interceptor/interceptor.go @@ -25,15 +25,22 @@ func NewInterceptor(name string, urlWhitelist map[string]int) grpc.UnaryServerIn 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))) + } + 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) - if s.Code() != 0 && s.Code() < 1000 { + ss, _ := status.FromError(err) + if ss.Code() != 0 && ss.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))) + zap.Any("resp", resp), zap.Error(err), zap.String("stack", gerrors.GetErrorStack(ss))) } return } diff --git a/test/tcp_conn/main.go b/test/tcp_conn/main.go index 2ac287d..be57de6 100644 --- a/test/tcp_conn/main.go +++ b/test/tcp_conn/main.go @@ -67,7 +67,8 @@ func (c *TcpClient) Output(pt pb.PackageType, requestId int64, message proto.Mes func (c *TcpClient) Start() { //connect, err := net.Dial("tcp", "111.229.238.28:8080") - connect, err := net.Dial("tcp", "im-tcp-connect.izhyin.com:8001") + //connect, err := net.Dial("tcp", "im-tcp-connect.izhyin.com:8001") + connect, err := net.Dial("tcp", "im-tcp-connect.zhiyingos.com:8001") if err != nil { log.Println(err) return @@ -87,7 +88,7 @@ func (c *TcpClient) SignIn() { signIn := pb.SignInInput{ UserId: c.UserId, DeviceId: c.DeviceId, - Token: "ZDNMWLHJYMDYHKBWESEVHQWXFPCLAGMIUWFOHWNI", + Token: "DIGHPXERETPBZWVFSOCBUTMUFONSLDUZZBADYLLR", } c.Output(pb.PackageType_PT_SIGN_IN, time.Now().UnixNano(), &signIn) }