//go:build !windows package winsvc import ( "context" "log/slog" "os" "os/signal" "syscall" "time" ) func RegisterShutdownHandler(ctx context.Context, shutdownFunc func(context.Context) error) { sigCh := make(chan os.Signal, 1) signal.Notify(sigCh, syscall.SIGTERM, syscall.SIGINT) <-sigCh slog.Info("shutdown signal received") shutdownCtx, cancel := context.WithTimeout(ctx, 30*time.Second) defer cancel() if err := shutdownFunc(shutdownCtx); err != nil { slog.Error("shutdown error", "err", err) os.Exit(1) } os.Exit(0) }