September 2017
Intermediate to advanced
466 pages
9h 33m
English
This subsection will teach you how to create a Go application that can handle three different signals: the name of the program will be h2s.go, and it will handle the SIGTERM, SIGINT, and SIGHUP signals.
The Go code of h2s.go will be presented in four parts.
The first part of the program contains the expected preamble:
package main import ( "fmt" "os" "os/signal" "syscall" "time" )
The second part has the following Go code:
func handleSignal(signal os.Signal) {
fmt.Println("* Got:", signal)
}
func main() {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP)
Here, the last statement tells you that the program will only handle the os.Interrupt, syscall.SIGTERM ...
Read now
Unlock full access