From a6ad16fc2b12386d7141e51c9506c3af74229281 Mon Sep 17 00:00:00 2001 From: xengineering Date: Sat, 21 Mar 2026 17:02:00 +0100 Subject: tools: websocket: Add wait for CTRL-C Now the connection is immediately established but just closed on SIGTERM and SIGINT. This allows to keep the connection for some time and lets the user decide when to stop. --- tools/websocket.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/websocket.go b/tools/websocket.go index 575bcd5..fc76d56 100644 --- a/tools/websocket.go +++ b/tools/websocket.go @@ -13,6 +13,7 @@ import ( "net/url" "os" "os/signal" + "syscall" "github.com/gorilla/websocket" ) @@ -31,6 +32,8 @@ func main() { log.Fatal(err) } defer c.Close() + + Await(syscall.SIGTERM, syscall.SIGINT) } func getURL() url.URL { @@ -45,3 +48,12 @@ func getURL() url.URL { return *maybeURL } + +func Await(signals ...os.Signal) { + listener := make(chan os.Signal, 1) + signal.Notify(listener, signals...) + defer signal.Stop(listener) + + sig := <-listener + log.Printf("Received OS signal '%v'\n", sig) +} -- cgit v1.3