Implement graceful shutdown

- Shutdown the HTTP server before exiting
- Persist data to store before exiting, if applicable
This commit is contained in:
TwinProduction
2021-02-05 20:45:28 -05:00
parent 8698736e7d
commit 8e2a2c4dbc
7 changed files with 79 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package controller
import (
"bytes"
"compress/gzip"
"context"
"encoding/json"
"fmt"
"log"
@ -59,7 +60,15 @@ func Handle() {
if os.Getenv("ROUTER_TEST") == "true" {
return
}
log.Fatal(server.ListenAndServe())
log.Println("[controller][Handle]", server.ListenAndServe())
}
// Shutdown stops the server
func Shutdown() {
if server != nil {
_ = server.Shutdown(context.TODO())
server = nil
}
}
// CreateRouter creates the router for the http server