diff --git a/cmd/api/server.go b/cmd/api/server.go index 0a274fe4..f515ffbb 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -113,8 +113,6 @@ func run() error { } } } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() go func() { // 服务连接 @@ -141,6 +139,9 @@ func run() error { quit := make(chan os.Signal) signal.Notify(quit, os.Interrupt) <-quit + + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() fmt.Printf("%s Shutdown Server ... \r\n", pkg.GetCurrentTimeStr()) if err := srv.Shutdown(ctx); err != nil {