重构代码结构,优化连接管理和日志记录

This commit is contained in:
2025-02-28 09:45:31 +08:00
parent 037c2c53c6
commit 06bcaf8bc7
15 changed files with 82 additions and 102 deletions

View File

@@ -37,6 +37,7 @@ func Start() {
defer close(errQuit)
// 启动服务
slog.Info("启动服务")
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -55,9 +56,9 @@ func Start() {
// 等待退出信号
select {
case <-osQuit:
slog.Info("服务关闭")
slog.Info("服务主动退出")
case <-errQuit:
slog.Error("服务异常退出")
slog.Warn("服务异常退出")
}
// 退出服务
@@ -69,11 +70,13 @@ func Start() {
close(wgCh)
select {
case <-timeout.Done():
slog.Warn("关闭超时,强制关闭")
case <-wgCh:
slog.Debug("服务已退出")
slog.Info("服务已退出")
case <-timeout.Done():
slog.Warn("退出超时,强制退出")
}
time.Sleep(3 * time.Second)
}
func initLog() {