Graceful shutdown for any kind of net.Listener in Go.
go get github.com/ernestoalejo/graceful-listener
package main
import (
"log"
"github.com/ernestoalejo/graceful-listener"
)
func main() {
listener, err := graceful.NewListener("localhost:3000")
if err != nil {
log.Fatal(err)
}
// ... use listener
}
The listener will close inmediatly after receiving SIGINT or SIGTERM and executing all the provided callbacks.