1
0
Fork 0

added an function to graceful shut down the server.

Dieser Commit ist enthalten in:
Sebastian Tobie 2021-01-11 22:39:33 +01:00
Ursprung f2de0903cd
Commit 97307bc3d8
1 geänderte Dateien mit 11 neuen und 0 gelöschten Zeilen

11
http.go
Datei anzeigen

@ -1,8 +1,10 @@
package httpserver
import (
"context"
"crypto/tls"
"net/http"
"time"
"github.com/gin-gonic/gin"
"github.com/pelletier/go-toml"
@ -91,6 +93,15 @@ func (s *Server) UseAuthBackend(a auth.AuthenticationHandler) {
s.authhf = a
}
// Stop Shuts the Server down
func (s *Server) Stop() {
ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(time.Second*5))
go func() {
log.Info().Err(s.http.Shutdown(ctx)).Msg("Server Shut down.")
}()
<-ctx.Done()
}
// Site is an Interface to abstract the modularized group of pages.
// The Middleware must be able to detect multiple calls byy itself. Deduplication is not performed.
type Site interface {