package main

import (
	"context"
	"log"
	"net/http"
	"sync"
	"time"

	"github.com/getsentry/sentry-go"
)

func shutdownHTTP(ctx context.Context, wg *sync.WaitGroup, srv *http.Server) {
	defer wg.Done()

	hub := sentry.CurrentHub().Clone()
	defer hub.Flush(10 * time.Second)

	ctx2, cancel := context.WithTimeout(ctx, 10*time.Second)
	defer cancel()
	if err := srv.Shutdown(ctx2); err != nil {
		hub.CaptureException(err)
		log.Printf("Error shutting down HTTP server: %v", err)
	}
}
