From 9d8aa2c5b7548088f87c4c05ec8221fb88f790df Mon Sep 17 00:00:00 2001 From: Snoosaphone Date: Sat, 28 Dec 2019 01:13:45 -0600 Subject: [PATCH] Adding the initial commit of the SigChan library. Later additions will include the ability to set a custom callback upon receiving the interrupt signal. --- main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 main.go diff --git a/main.go b/main.go new file mode 100644 index 0000000..de45693 --- /dev/null +++ b/main.go @@ -0,0 +1,19 @@ +package sigchan + +import ( + "fmt" + "log" + "os" + "os/signal" +) + +// SigChan listens for os interrupt signals and gracefully exits the program. +func SigChan() { + sigchan := make(chan os.Signal, 10) + signal.Notify(sigchan, os.Interrupt) + <-sigchan + fmt.Println() + log.Println("Received CTRL+C interrupt. Program killed!") + + os.Exit(0) +}