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 }