Browse Source

update

master
DengBiao 2 years ago
parent
commit
d769e2cbdd
1 changed files with 28 additions and 0 deletions
  1. +28
    -0
      pkg/interceptor/interceptor.go

+ 28
- 0
pkg/interceptor/interceptor.go View File

@@ -21,6 +21,20 @@ 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)))
//}
if err != nil {
return
}

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))
@@ -62,3 +76,17 @@ func handleWithAuth(ctx context.Context, req interface{}, info *grpc.UnaryServer
}
return handler(ctx, req)
}

// handleMasterAuth 处理站长权限
func handleMasterAuth(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, 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 handler(ctx, req)
}

Loading…
Cancel
Save