diff --git a/go.mod b/go.mod index 0a5ec84..ff20217 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,5 @@ module github.com/digitalocean/sample-golang -go 1.13 +go 1.22 -require github.com/gofrs/uuid v3.3.0+incompatible // indirect +require github.com/gofrs/uuid v4.4.0+incompatible diff --git a/go.sum b/go.sum index 4b1328f..c0ad687 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,2 @@ -github.com/gofrs/uuid v1.2.0 h1:coDhrjgyJaglxSjxuJdqQSSdUpG3w6p1OwN2od6frBU= -github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84= -github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= +github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA= +github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= diff --git a/main.go b/main.go index 43d1ce5..1fb184f 100644 --- a/main.go +++ b/main.go @@ -4,8 +4,10 @@ import ( "fmt" "net/http" "os" + "os/signal" "strconv" "strings" + "syscall" "github.com/gofrs/uuid" ) @@ -127,6 +129,16 @@ func main() { fmt.Println() fmt.Printf("==> Server listening at %s 🚀\n", bindAddr) + sigCh := make(chan os.Signal, 1) + signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGKILL) + go func() { + fmt.Println("Waiting for shutdown signal...") + sig := <-sigCh + fmt.Printf("Shutdown signal received: %s\n", sig) + // Perform cleanup or shutdown here + os.Exit(0) + }() + if err := http.ListenAndServe(bindAddr, nil); err != nil { panic(err) }