Implemented graceful shutdown
This commit is contained in:
parent
a97216fbd1
commit
2644141953
23
main.go
23
main.go
|
@ -5,6 +5,10 @@ import (
|
|||
"git.mowie.cc/konrad/Library/routes"
|
||||
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
"os/signal"
|
||||
"context"
|
||||
)
|
||||
|
||||
// UserLogin Object to recive user credentials in JSON format
|
||||
|
@ -30,5 +34,22 @@ func main() {
|
|||
// Start the webserver
|
||||
e := routes.NewEcho()
|
||||
routes.RegisterRoutes(e)
|
||||
e.Start(models.Config.Interface)
|
||||
// Start server
|
||||
go func() {
|
||||
if err := e.Start(models.Config.Interface); err != nil {
|
||||
e.Logger.Info("shutting down the server")
|
||||
}
|
||||
}()
|
||||
|
||||
// Wait for interrupt signal to gracefully shutdown the server with
|
||||
// a timeout of 10 seconds.
|
||||
quit := make(chan os.Signal)
|
||||
signal.Notify(quit, os.Interrupt)
|
||||
<-quit
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
|
||||
defer cancel()
|
||||
fmt.Println("Shutting down...")
|
||||
if err := e.Shutdown(ctx); err != nil {
|
||||
e.Logger.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue