From a8f7c3b91dc0c185443e3d2c3549c0d118c61fb3 Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Mon, 28 Jul 2025 16:19:53 +0800 Subject: [PATCH] fix --- internal/container/container.go | 1 + internal/shared/http/router.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/internal/container/container.go b/internal/container/container.go index 87689e3..b2612b8 100644 --- a/internal/container/container.go +++ b/internal/container/container.go @@ -656,6 +656,7 @@ func RegisterRoutes( if err := router.Start(addr); err != nil { logger.Error("HTTP服务器启动失败", zap.Error(err)) + // 在goroutine中记录错误,但不会影响主程序 } else { logger.Info("HTTP服务器启动成功", zap.String("addr", addr)) } diff --git a/internal/shared/http/router.go b/internal/shared/http/router.go index 771323c..4d9ec2a 100644 --- a/internal/shared/http/router.go +++ b/internal/shared/http/router.go @@ -99,9 +99,13 @@ func (r *GinRouter) Start(addr string) error { // 启动服务器 if err := r.server.ListenAndServe(); err != nil && err != http.ErrServerClosed { + r.logger.Error("HTTP服务器启动失败", + zap.String("addr", addr), + zap.Error(err)) return fmt.Errorf("failed to start server: %w", err) } + r.logger.Info("HTTP服务器启动成功", zap.String("addr", addr)) return nil }