Later additions will include the ability to set a custom callback upon receiving the interrupt signal.
20 lines
332 B
Go
20 lines
332 B
Go
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)
|
|
}
|