From fb409de4b6ad6bf4d4d0c5ddf652687fdfe7bacb Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期二, 12 九月 2023 14:55:04 +0800 Subject: [PATCH] 仓库增删改查接口 --- 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