diff --git a/main.go b/main.go index 18805dd..5f063f5 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,23 @@ import ( ) func main() { - setupJsonApi() - http.ListenAndServe(":80", nil) + setupJsonApi() + + server := &http.Server{ + Addr: ":80", + } + + go func() { + if err := server.ListenAndServe(); err != nil { + fmt.Println("Server error:", err) + } + }() + + // Graceful shutdown on interrupt signal + interruptSignal := make(chan os.Signal, 1) + signal.Notify(interruptSignal, os.Interrupt) + <-interruptSignal + + fmt.Println("Shutting down gracefully...") + server.Shutdown(context.Background()) }