Clean exit when Ctrl+C arrives
authorJavier Sancho <jsf@jsancho.org>
Mon, 27 Nov 2017 16:29:57 +0000 (17:29 +0100)
committerJavier Sancho <jsf@jsancho.org>
Mon, 27 Nov 2017 16:29:57 +0000 (17:29 +0100)
midgaard_bot.go

index a11ab8a..26278aa 100644 (file)
@@ -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")
 }