Skip to content

Latest commit

 

History

History
38 lines (28 loc) · 656 Bytes

README.md

File metadata and controls

38 lines (28 loc) · 656 Bytes

GoDoc

shutdown

Utility library to handle daemons

Usage

import (
    "net"

    "github.com/KarpelesLab/shutdown"
)

func main() {
    shutdown.SetupSignals()

    // do the things you want to do
    go launchHttp()

    shutdown.Wait()
}

func launchHttp() {
    l, err := net.Listen("tcp", ":80")
    if err != nil {
        shutdown.Fatalf("failed to listen for the http server: %w", err)
        return
    }

    // cleanup of opened listen socket
    shutdown.Defer(func() {
        l.Close()
    })
    // ...
}