more graceful shutdown options

This commit is contained in:
Gardient
2018-11-11 00:01:20 +02:00
parent 8c32721aa9
commit 417cd8763f

View File

@@ -9,18 +9,32 @@ import (
"time"
)
// StartHTTPServer cct
func StartHTTPServer(address string, handler http.HandlerFunc) {
// StartHTTPServerHandler cct
func StartHTTPServerHandler(address string, handler http.Handler) {
mux := http.NewServeMux()
mux.Handle("/", handler)
srv := &http.Server{Addr: address, Handler: mux}
startServer(srv)
}
// StartHTTPServerHandlerFunc cct
func StartHTTPServerHandlerFunc(address string, handler http.HandlerFunc) {
mux := http.NewServeMux()
mux.HandleFunc("/", handler)
srv := &http.Server{Addr: address}
http.HandleFunc("/", handler)
startServer(srv)
}
func startServer(srv *http.Server) {
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
srv := &http.Server{Addr: address}
http.HandleFunc("/", handler)
go func() {
log.Print("listening on http://" + address)
log.Print("listening on http://" + srv.Addr)
if err := srv.ListenAndServe(); err != nil {
log.Fatal(err)