Skip to content

syossan27/tebata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Simple linux signal handler for golang

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages