优化服务启动流程

This commit is contained in:
2025-05-14 15:13:44 +08:00
parent d69a77df38
commit f86cf47e86
7 changed files with 243 additions and 123 deletions

View File

@@ -37,11 +37,7 @@ func New(config *Config) *Service {
}
}
func (s *Service) Close() {
s.cancel()
}
func (s *Service) Run() {
func (s *Service) Run() error {
slog.Info("启动 fwd 服务")
errQuit := make(chan struct{}, 2)
@@ -79,7 +75,7 @@ func (s *Service) Run() {
slog.Info("fwd 服务主动退出")
case <-errQuit:
slog.Warn("fwd 服务异常退出")
s.Close()
s.Stop()
}
wg.Wait()
@@ -103,4 +99,10 @@ func (s *Service) Run() {
slog.Debug("转发服务已关闭")
wg.Wait()
slog.Info("fwd 服务已退出")
return nil
}
func (s *Service) Stop() {
s.cancel()
}