| 64 | } |
| 65 | |
| 66 | func shutdownOnInterruptSignal(server *http.Server, timeout time.Duration, shutdown chan<- error) { |
| 67 | interrupt := make(chan os.Signal, 1) |
| 68 | notifySignal(interrupt, os.Interrupt) |
| 69 | |
| 70 | go func() { |
| 71 | <-interrupt |
| 72 | log.Info().Msg("Received interrupt. Shutting down...") |
| 73 | ctx, cancel := context.WithTimeout(context.Background(), timeout) |
| 74 | defer cancel() |
| 75 | if err := serverShutdown(server, ctx); err != nil { |
| 76 | shutdown <- err |
| 77 | } |
| 78 | }() |
| 79 | } |
| 80 | |
| 81 | func waitForServerToClose(shutdown <-chan error) error { |
| 82 | err := <-shutdown |