zhangqian
2024-03-27 138fddee3dc30b49e78ffef63c51706f1463a021
main.go
@@ -6,10 +6,10 @@
   "os"
   "os/signal"
   "outsourcing/conf"
   "outsourcing/constvar"
   "outsourcing/models"
   "outsourcing/pkg/logx"
   "outsourcing/router"
   "outsourcing/service"
   "syscall"
   "time"
)
@@ -38,18 +38,14 @@
      ReadTimeout:  5 * time.Second,
      WriteTimeout: 5 * time.Second,
   }
   go service.InitApsServiceConn()
   go shutdown(server)
   logx.Error(server.ListenAndServe().Error())
}
func shutdown(server *http.Server) {
   quit := make(chan os.Signal, 1)
   signal.Notify(quit, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGTERM)
   <-quit
   if constvar.GrpcClient != nil {
      _ = constvar.GrpcClient.Close()
   }
   // 创建一个上下文,设置超时时间
   ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
   defer cancel()
@@ -58,5 +54,8 @@
      logx.Warnf("服务优雅退出失败: %v", err)
      return
   }
   service.CloseApsServiceConn()
   logx.Infof("server exited success")
}