This commit is contained in:
lbenedar
2026-03-19 18:38:22 +03:00
parent 46a1bb868b
commit 16f2caee66
3 changed files with 22 additions and 4 deletions

View File

@@ -36,7 +36,18 @@ func (app *application) serve() error {
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
shutdownError <- srv.Shutdown(ctx)
err := srv.Shutdown(ctx)
if err != nil {
shutdownError <- err
}
app.logger.PrintInfo("completing background tasks", map[string]string{
"addr": srv.Addr,
})
app.wg.Wait()
shutdownError <- nil
}()
app.logger.PrintInfo("starting server", map[string]string{
@@ -49,13 +60,14 @@ func (app *application) serve() error {
return err
}
app.logger.PrintInfo("stopped server", map[string]string{
"addr": srv.Addr,
})
err = <-shutdownError
if err != nil {
return err
}
app.logger.PrintInfo("stopped server", map[string]string{
"addr": srv.Addr,
})
return nil
}