diff options
| author | xengineering <me@xengineering.eu> | 2026-03-21 17:02:00 +0100 |
|---|---|---|
| committer | xengineering <me@xengineering.eu> | 2026-03-22 10:23:46 +0100 |
| commit | a6ad16fc2b12386d7141e51c9506c3af74229281 (patch) | |
| tree | fded42cca0731c1cb6fdca4a058416d0d2679c23 /tools/websocket.go | |
| parent | 139572f5221abd3f6ce1f0627982974ab3fa5531 (diff) | |
| download | sia-server-a6ad16fc2b12386d7141e51c9506c3af74229281.tar sia-server-a6ad16fc2b12386d7141e51c9506c3af74229281.tar.zst sia-server-a6ad16fc2b12386d7141e51c9506c3af74229281.zip | |
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.
Diffstat (limited to 'tools/websocket.go')
| -rw-r--r-- | tools/websocket.go | 12 |
1 files changed, 12 insertions, 0 deletions
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) +} |
