Simple linux signal handler for Go
go get -u github.com/syossan27/tebata
package main
import (
"fmt"
"strconv"
"syscall"
"github.com/syossan27/tebata"
)
func main() {
t := tebata.New(syscall.SIGINT, syscall.SIGTERM)
// Do function when catch signal.
t.Reserve(sum, 1, 2)
t.Reserve(hello)
t.Reserve(os.Exit, 0)
for {
// Do something
}
}
func sum(firstArg, secondArg int) {
fmt.Println(strconv.Itoa(firstArg + secondArg))
}
func hello() {
fmt.Println("Hello")
}
// Expect output when type Ctrl + C:
// 3
// Hello
Look this article.
How to implement a signal handler in Go
The Go gopher was designed by Renée French.
The gopher side portrait is designed by Takuya Ueda.
Licensed under the "Creative CommonsAttribution 3.0" license.