/tebata

Simple linux signal handler for golang

Primary LanguageGoMIT LicenseMIT

Tebata(手旗)

GoDoc MIT License

logo

Overview

Simple linux signal handler for Go

Installation

go get -u github.com/syossan27/tebata

Usage

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

Why?

Look this article.

How to implement a signal handler in Go

Artwork credits

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.