Look for sigint

This commit is contained in:
2025-10-10 20:16:09 +02:00
parent 1e5ac81598
commit 2c727632b8

14
main.go
View File

@@ -6,6 +6,7 @@ import (
"fmt"
"net/http"
"os"
"os/signal"
"strings"
logger "git.site.quack-lab.dev/dave/cylogger"
@@ -57,7 +58,6 @@ func main() {
w.Write([]byte("EVE PI Server Running"))
})
// Start server
server := &http.Server{
Addr: ":3000",
Handler: mux,
@@ -89,6 +89,18 @@ func main() {
w.WriteHeader(http.StatusOK)
w.Write([]byte("Authenticated! Access token: " + token))
})
// Listen for SIGINT and gracefully shut down the server
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, os.Interrupt)
<-sigCh
logger.Info("SIGINT received, shutting down web server gracefully...")
if err := server.Shutdown(context.Background()); err != nil {
logger.Error("Error shutting down server: %v", err)
} else {
logger.Info("Web server shut down cleanly")
}
}
func LoadOptions() (Options, error) {