diff --git a/http.go b/http.go index 88117d9..dcd53ec 100644 --- a/http.go +++ b/http.go @@ -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 {