about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBen Morrison <ben@gbmor.dev>2019-03-19 23:10:07 -0400
committerBen Morrison <ben@gbmor.dev>2019-03-19 23:10:07 -0400
commit9746058458dc6b018a5755753e4adeb6540b9c23 (patch)
treed809bd9d9cfb4a36c1a35fef634063c8f9a17ad0
parent2b804acf50d43748c9adaed5b9f36cd38e5dc1b7 (diff)
downloadgoofbot-9746058458dc6b018a5755753e4adeb6540b9c23.tar.gz
now handling SIGINT (^C) gracefully
-rw-r--r--main.go17
1 files 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)
+	}()
 }