| | |
| | | "os" |
| | | "os/signal" |
| | | "outsourcing/conf" |
| | | "outsourcing/constvar" |
| | | "outsourcing/models" |
| | | "outsourcing/pkg/logx" |
| | | "outsourcing/router" |
| | | "outsourcing/service" |
| | | "syscall" |
| | | "time" |
| | | ) |
| | |
| | | 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() |
| | |
| | | logx.Warnf("服务优雅退出失败: %v", err) |
| | | return |
| | | } |
| | | |
| | | service.CloseApsServiceConn() |
| | | |
| | | logx.Infof("server exited success") |
| | | } |