more graceful shutdown options
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user