Add error reporting on http server startup failure

master
Bas Kloosterman 12 months ago
parent 5dc9f6c1b0
commit 2600aa03a5
  1. 5
      dvzaservice/main.go
  2. 4
      dvzaservice/srv.go
  3. 5
      whiteboxservice/main.go
  4. 6
      whiteboxservice/srv.go

@ -6,6 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"net" "net"
"net/http"
"os" "os"
"os/signal" "os/signal"
"sync" "sync"
@ -96,7 +97,9 @@ func main() {
go func() { go func() {
wg.Add(1) wg.Add(1)
srv.ListenAndServe() if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
panic(err)
}
}() }()
<-stop <-stop

@ -34,12 +34,12 @@ func (srv *UIService) Addr() string {
return srv.srv.Addr return srv.srv.Addr
} }
func (srv *UIService) ListenAndServe() { func (srv *UIService) ListenAndServe() error {
if !srv.inited { if !srv.inited {
srv.init() srv.init()
} }
log.Printf("Listening on %v\n", srv.srv.Addr) log.Printf("Listening on %v\n", srv.srv.Addr)
srv.srv.ListenAndServe() return srv.srv.ListenAndServe()
} }
func (srv *UIService) Shutdown(ctx context.Context) error { func (srv *UIService) Shutdown(ctx context.Context) error {

@ -7,6 +7,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"net" "net"
"net/http"
"os" "os"
"os/signal" "os/signal"
"sync" "sync"
@ -103,7 +104,9 @@ func main() {
go func() { go func() {
wg.Add(1) wg.Add(1)
srv.ListenAndServe() if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
panic(err)
}
}() }()
<-stop <-stop

@ -39,12 +39,12 @@ func (srv *UIService) Addr() string {
return srv.srv.Addr return srv.srv.Addr
} }
func (srv *UIService) ListenAndServe() { func (srv *UIService) ListenAndServe() error {
if !srv.inited { if !srv.inited {
srv.init() srv.init()
} }
log.Println("Listening on %v", srv.srv.Addr) log.Printf("Listening on %v\n", srv.srv.Addr)
srv.srv.ListenAndServe() return srv.srv.ListenAndServe()
} }
func (srv *UIService) Shutdown(ctx context.Context) error { func (srv *UIService) Shutdown(ctx context.Context) error {

Loading…
Cancel
Save