func()

in pkg/server/server.go [74:104]


func (p *Server) ListenUntilContextCancelled(ctx context.Context) {
	log := logger.FromContext(ctx)
	p.configureHandler()

	// Run the server in a goroutine
	go func() {
		log.Info("Starting server...")
		if err := p.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
			log.Fatalf("Unable to start server: %v", err)
		}
		log.Debug("Server has stopped listening")
	}()

	// Block until a signal is received
	select {
	case <-ctx.Done():
	}

	log.Info("Shutting down server...")

	// Create a context with a timeout for the graceful shutdown
	ctx, cancel := context.WithTimeout(context.Background(), maxTerminationWait)
	defer cancel()

	// Shutdown the server and wait for existing connections to be closed
	if err := p.server.Shutdown(ctx); err != nil {
		log.Fatalf("Server shutdown error: %v", err)
	}

	log.Info("Server gracefully stopped")
}