Skip to content

x-mod/sigtrap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sigtrap

simple signal traps

Quick Start

package main

import (
	"context"
	"log"
	"syscall"

	"github.com/x-mod/sigtrap"
)

func main() {
	ctx, cancel := context.WithCancel(context.Background())
	c := sigtrap.New(
		sigtrap.Trap(syscall.SIGINT, sigtrap.Handler(cancel)),
		sigtrap.Trap(syscall.SIGTERM, sigtrap.Handler(cancel)),
	)
	defer c.Close()
	log.Println("sigtrap: waiting ...")
	log.Println("sigtrap:", c.Serve(ctx))
}

type CTRL+C send SIGINT signal, then invoke the cancel function.

About

simple package for signal traps

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages