|
|
@@ -1,7 +1,6 @@
|
|
1
|
1
|
package webx
|
|
2
|
2
|
|
|
3
|
3
|
import (
|
|
4
|
|
- "context"
|
|
5
|
4
|
"fmt"
|
|
6
|
5
|
"log"
|
|
7
|
6
|
"net/http"
|
|
|
@@ -13,7 +12,6 @@ import (
|
|
13
|
12
|
|
|
14
|
13
|
"git.x2erp.com/qdy/go-base/client"
|
|
15
|
14
|
"git.x2erp.com/qdy/go-base/config/subconfigs"
|
|
16
|
|
- "git.x2erp.com/qdy/go-base/container"
|
|
17
|
15
|
"git.x2erp.com/qdy/go-base/logger"
|
|
18
|
16
|
)
|
|
19
|
17
|
|
|
|
@@ -202,42 +200,42 @@ func (s *WebService) RunTLS(serviceName, certFile, keyFile string) {
|
|
202
|
200
|
//s.waitForServiceShutdown(containerFactory)
|
|
203
|
201
|
}
|
|
204
|
202
|
|
|
205
|
|
-// waitForServiceShutdown 等待单个服务关闭
|
|
206
|
|
-func (s *WebService) WaitForServiceShutdown(containerFactory *container.ContainerFactory) {
|
|
|
203
|
+// // waitForServiceShutdown 等待单个服务关闭
|
|
|
204
|
+// func (s *WebService) WaitForServiceShutdown(containerFactory *container.ContainerFactory) {
|
|
207
|
205
|
|
|
208
|
|
- log.Printf("按 Ctrl+C 停止服务 %s", s.serviceName)
|
|
|
206
|
+// log.Printf("按 Ctrl+C 停止服务 %s", s.serviceName)
|
|
209
|
207
|
|
|
210
|
|
- // 等待信号
|
|
211
|
|
- <-s.quit
|
|
212
|
|
- log.Printf("接收到终止信号,正在优雅关闭服务 %s...", s.serviceName)
|
|
|
208
|
+// // 等待信号
|
|
|
209
|
+// <-s.quit
|
|
|
210
|
+// log.Printf("接收到终止信号,正在优雅关闭服务 %s...", s.serviceName)
|
|
213
|
211
|
|
|
214
|
|
- //退出注册中心
|
|
215
|
|
- //consul.Deregister(s.serviceName, s.Ip, s.Port, b.Cfg.GetConsulConfig())
|
|
|
212
|
+// //退出注册中心
|
|
|
213
|
+// //consul.Deregister(s.serviceName, s.Ip, s.Port, b.Cfg.GetConsulConfig())
|
|
216
|
214
|
|
|
217
|
|
- // 创建关闭上下文,给30秒完成当前请求
|
|
218
|
|
- ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
219
|
|
- defer cancel()
|
|
|
215
|
+// // 创建关闭上下文,给30秒完成当前请求
|
|
|
216
|
+// ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
|
|
217
|
+// defer cancel()
|
|
220
|
218
|
|
|
221
|
|
- // 停止接收新请求,完成当前请求
|
|
222
|
|
- if err := s.httpServer.Shutdown(ctx); err != nil {
|
|
223
|
|
- log.Printf("服务 %s 关闭失败: %v", s.serviceName, err)
|
|
224
|
|
- } else {
|
|
225
|
|
- log.Printf("服务 %s 已关闭", s.serviceName)
|
|
226
|
|
- }
|
|
|
219
|
+// // 停止接收新请求,完成当前请求
|
|
|
220
|
+// if err := s.httpServer.Shutdown(ctx); err != nil {
|
|
|
221
|
+// log.Printf("服务 %s 关闭失败: %v", s.serviceName, err)
|
|
|
222
|
+// } else {
|
|
|
223
|
+// log.Printf("服务 %s 已关闭", s.serviceName)
|
|
|
224
|
+// }
|
|
227
|
225
|
|
|
228
|
|
- // 执行关闭处理
|
|
229
|
|
- if containerFactory != nil {
|
|
230
|
|
- containerFactory.CloseAll()
|
|
231
|
|
- }
|
|
|
226
|
+// // 执行关闭处理
|
|
|
227
|
+// if containerFactory != nil {
|
|
|
228
|
+// containerFactory.CloseAll()
|
|
|
229
|
+// }
|
|
232
|
230
|
|
|
233
|
|
- // 停止日志写入
|
|
234
|
|
- logger.StopESWriter()
|
|
235
|
|
- log.Printf("服务 %s 优雅关闭完成", s.serviceName)
|
|
|
231
|
+// // 停止日志写入
|
|
|
232
|
+// logger.StopESWriter()
|
|
|
233
|
+// log.Printf("服务 %s 优雅关闭完成", s.serviceName)
|
|
236
|
234
|
|
|
237
|
|
- // 等待一小段时间确保日志写入完成
|
|
238
|
|
- time.Sleep(100 * time.Millisecond)
|
|
239
|
|
- os.Exit(0)
|
|
240
|
|
-}
|
|
|
235
|
+// // 等待一小段时间确保日志写入完成
|
|
|
236
|
+// time.Sleep(100 * time.Millisecond)
|
|
|
237
|
+// os.Exit(0)
|
|
|
238
|
+// }
|
|
241
|
239
|
|
|
242
|
240
|
// AddMiddleware 添加中间件
|
|
243
|
241
|
func (s *WebService) AddMiddleware(middleware func(http.Handler) http.Handler) {
|