From: Javier Sancho Date: Mon, 27 Nov 2017 16:29:57 +0000 (+0100) Subject: Clean exit when Ctrl+C arrives X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=1fd30cb70efb466102134634df0c6de907f70f88;p=midgaard_bot.git Clean exit when Ctrl+C arrives --- 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") }