first commit
This commit is contained in:
21
closehandle.go
Normal file
21
closehandle.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// SetupCloseHandler creates a 'listener' on a new goroutine which will notify the
|
||||
// program if it receives an interrupt from the OS. We then handle this by calling
|
||||
// our clean up procedure and exiting the program.
|
||||
func SetupCloseHandler() {
|
||||
c := make(chan os.Signal, 2)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
fmt.Println("\r- Ctrl+C pressed in Terminal")
|
||||
os.Exit(0)
|
||||
}()
|
||||
}
|
||||
Reference in New Issue
Block a user