From 9746058458dc6b018a5755753e4adeb6540b9c23 Mon Sep 17 00:00:00 2001 From: Ben Morrison Date: Tue, 19 Mar 2019 23:10:07 -0400 Subject: now handling SIGINT (^C) gracefully --- main.go | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index a206861..5b9c2c6 100644 --- a/main.go +++ b/main.go @@ -10,6 +10,7 @@ import ( "log" "os" "os/exec" + "os/signal" "strconv" "strings" "time" @@ -187,12 +188,12 @@ func main() { if err := client.Connect(); err != nil { log.Fatalf("an error occurred while attempting to connect to %s: %s", client.Server(), err) } - // TODO: figure out sigint handling - // ctrlc := make(chan os.Signal, 1) - // signal.Notify(ctrlc, os.Interrupt) - // go func() { - // <-ctrlc - // client.Close() - // os.Exit(1) - // }() + // sigint handling + ctrlc := make(chan os.Signal, 1) + signal.Notify(ctrlc, os.Interrupt) + go func() { + <-ctrlc + client.Close() + os.Exit(1) + }() } -- cgit 1.4.1-2-gfad0