fix: error from golangci-lint tool (#623)

This commit is contained in:
Bo-Yi Wu
2021-08-03 14:44:00 +08:00
committed by GitHub
parent 349c0c8c1d
commit 0a8d801380
15 changed files with 74 additions and 164 deletions

View File

@@ -7,6 +7,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
// generate protobuffs
@@ -41,7 +42,7 @@ func (c *healthClient) Check(ctx context.Context) (bool, error) {
}
return false, nil
}
switch grpc.Code(err) {
switch status.Code(err) {
case
codes.Aborted,
codes.DataLoss,

View File

@@ -8,6 +8,7 @@ import (
"github.com/appleboy/gorush/rpc"
"google.golang.org/grpc"
"google.golang.org/grpc/status"
)
const (
@@ -27,7 +28,7 @@ func main() {
for {
ok, err := client.Check(context.Background())
if !ok || err != nil {
log.Printf("can't connect grpc server: %v, code: %v\n", err, grpc.Code(err))
log.Printf("can't connect grpc server: %v, code: %v\n", err, status.Code(err))
} else {
log.Println("connect the grpc server successfully")
}

View File

@@ -101,7 +101,12 @@ func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*prot
}
}
go notify.SendNotification(&notification, s.cfg)
go func() {
_, err := notify.SendNotification(&notification, s.cfg)
if err != nil {
logx.LogError.Error(err)
}
}()
return &proto.NotificationReply{
Success: true,
@@ -131,11 +136,9 @@ func RunGRPCServer(ctx context.Context, cfg *config.ConfYaml) error {
}
logx.LogAccess.Info("gRPC server is running on " + cfg.GRPC.Port + " port.")
go func() {
select {
case <-ctx.Done():
s.GracefulStop() // graceful shutdown
logx.LogAccess.Info("shutdown the gRPC server")
}
<-ctx.Done()
s.GracefulStop() // graceful shutdown
logx.LogAccess.Info("shutdown the gRPC server")
}()
if err = s.Serve(lis); err != nil {
logx.LogError.Fatalln(err)