GitHub - bufbuild/interrupt-go: A small helper library to handle interrupt signals in Go programs. · GitHub
Skip to content

About

A small helper library to handle interrupt signals in Go programs.

Resources

Code of conduct

Stars

3 stars

Watchers

4 watching

Forks

Repository files navigation

interrupt-go

Build Report Card GoDoc 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:

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.

About

A small helper library to handle interrupt signals in Go programs.

Resources

Code of conduct

Stars

3 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages