https://github.com/bufbuild/interrupt-go
A small helper library to handle interrupt signals in Go programs.
https://github.com/bufbuild/interrupt-go
Last synced: about 1 month ago
JSON representation
A small helper library to handle interrupt signals in Go programs.
- Host: GitHub
- URL: https://github.com/bufbuild/interrupt-go
- Owner: bufbuild
- License: apache-2.0
- Created: 2025-05-09T09:18:42.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-11-24T05:19:37.000Z (7 months ago)
- Last Synced: 2026-01-31T14:41:19.407Z (5 months ago)
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 3
- Watchers: 6
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# interrupt-go
[](https://github.com/bufbuild/interrupt-go/actions/workflows/ci.yaml)
[](https://goreportcard.com/report/buf.build/go/interrupt)
[](https://pkg.go.dev/buf.build/go/interrupt)
[](https://buf.build/links/slack)
This is a small helper Go library that exposes two types:
- `interrupt.Signals`: All OS-specific interrupt signals. This extends `os.Interrupt` with `syscall.SIGTERM` in unix-like systems.
- `interrupt.Handle`: A simple function to provide interrupt signal handling on a `context.Context`.
This will typically be used at the highest levels of an application:
```go
func main() {
// Handle returns a copy of the parent Context that is marked done
// when an interrupt signal arrives or when the parent Context's
// Done channel is closed, whichever happens first.
//
// Signal handling is unregistered automatically by this function when the
// first interrupt signal arrives, which will restore the default interrupt
// signal behavior of Go programs (to exit).
ctx := interrupt.Handle(context.Background())
// Use the ctx throughout the rest of your application.
// ...
}
```
## Status: Stable
This library is stable.
## Legal
Offered under the [Apache 2 license](https://github.com/bufbuild/interrupt-go/blob/main/LICENSE).