An open API service indexing awesome lists of open source software.

https://github.com/x-mod/sigtrap

simple package for signal traps
https://github.com/x-mod/sigtrap

Last synced: 5 months ago
JSON representation

simple package for signal traps

Awesome Lists containing this project

README

          

sigtrap
===

simple signal traps

## Quick Start

````go
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.