Signals is a simple package to intercept Interrupt signals.
go get -u czechia.dev/signals
package main
import (
"fmt"
"net/http"
"czechia.dev/signals"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello, World! 👋")
}
func main() {
fmt.Println("starting application")
go http.ListenAndServe(":8080", http.HandlerFunc(handler))
signals.Interrupt(func() error {
fmt.Println("interrupt signal received")
return nil
})
}