From 1fd30cb70efb466102134634df0c6de907f70f88 Mon Sep 17 00:00:00 2001 From: Javier Sancho Date: Mon, 27 Nov 2017 17:29:57 +0100 Subject: [PATCH] Clean exit when Ctrl+C arrives --- midgaard_bot.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/midgaard_bot.go b/midgaard_bot.go index a11ab8a..26278aa 100644 --- a/midgaard_bot.go +++ b/midgaard_bot.go @@ -21,6 +21,8 @@ package main import ( "context" "log" + "os" + "os/signal" "github.com/jessevdk/go-flags" ) @@ -48,10 +50,9 @@ func main() { log.Panic(err) } - for { - select { - case <-ctx.Done(): - break - } - } + intChannel := make(chan os.Signal, 1) + signal.Notify(intChannel, os.Interrupt) + <-intChannel + + log.Print("Exit") } -- 2.39.5