Change error comparison to use errors.Is() and add a line of whitespace before the if statement on graceful shutdown

This commit is contained in:
J. J. Bigorra 2020-11-11 08:37:00 +01:00
parent 7742ff50e0
commit b282d369e3

View File

@ -1793,7 +1793,7 @@ func main() {
// Initializing the server in a goroutine so that
// it won't block the graceful shutdown handling below
go func() {
if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
if err := srv.ListenAndServe(); err != nil && errors.Is(err, http.ErrServerClosed) {
log.Fatalf("listen: %s\n", err)
}
}()
@ -1812,6 +1812,7 @@ func main() {
// the request it is currently handling
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
if err := srv.Shutdown(ctx); err != nil {
log.Fatal("Server forced to shutdown:", err)
}