From 931e10ff09ed3bade33570755347367e3bf0f842 Mon Sep 17 00:00:00 2001
From: jiangshuai <291802688@qq.com>
Date: 星期四, 21 九月 2023 19:39:36 +0800
Subject: [PATCH] 1.修改出入库的验证逻辑方式
---
main.go | 24 ++++++++++++++----------
1 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/main.go b/main.go
index caf375b..3ee1279 100644
--- a/main.go
+++ b/main.go
@@ -1,13 +1,13 @@
package main
import (
+ "context"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"wms/conf"
- "wms/constvar"
"wms/models"
"wms/pkg/logx"
"wms/router"
@@ -30,10 +30,6 @@
return
}
- // 鍚姩APS RPC鏈嶅姟
- //safe.Go(service.StartAPServer)
-
- go shutdown()
logx.Infof("aps-server start serve...")
server := &http.Server{
Addr: ":" + conf.WebConf.Port,
@@ -41,16 +37,24 @@
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
}
-
+ go shutdown(server)
logx.Error(server.ListenAndServe().Error())
}
-func shutdown() {
+func shutdown(server *http.Server) {
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGINT, syscall.SIGTERM)
<-quit
- _ = constvar.GrpcClient.Close()
- logx.Infof("aps-server exited...")
- os.Exit(0)
+ logx.Infof("server exiting...")
+ // 鍒涘缓涓�涓笂涓嬫枃锛岃缃秴鏃舵椂闂�
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ defer cancel()
+
+ // 鍏抽棴HTTP鏈嶅姟鍣�
+ if err := server.Shutdown(ctx); err != nil {
+ logx.Infof("鏈嶅姟浼橀泤閫�鍑哄け璐�: %v", err)
+ return
+ }
+ logx.Infof("server exited")
}
--
Gitblit v1.8.0