Skip to content

renanbastos93/ossignals

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ossignals-go

This package helps us to use signals in Golang

How to install

$ go install github.com/renanbastos93/ossignals

How to use

package main

import (
	"fmt"
	"os"
	"syscall"

	"github.com/renanbastos93/ossignals"
)

func main() {
	// Show PID to you can send signals for thread main of this app
	fmt.Println("PID:", os.Getpid())

	// Create a new thread to listen signals received by operation system
	go ossignals.On(

		// Create actions to each signal
		ossignals.Actions{
			syscall.SIGTERM: func() bool {
				fmt.Println("I'm dying...")
				return true
			},
			syscall.SIGHUP: func() bool {
				// Here we can do reload a config, reload connections, or anything...
				fmt.Println("process anything...")
				return false
			},
			syscall.SIGINT: func() bool {
				fmt.Println("close by CTRL + C")
				return true
			},
		},
	)
	
	// When receiving true in the function defined in your actions thread main is finished.
	<-ossignals.Close
}

Case you don't know about signals in the operating system you can read this doc.

About

This package helps us to use signals in Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages