From ec7fcf63bb949805714c6a3244f5f5224ab3c943 Mon Sep 17 00:00:00 2001 From: Nicolas MASSE Date: Tue, 14 Dec 2021 10:43:08 +0100 Subject: [PATCH] log to stderr when the bot cannot bind http port --- http.go | 5 ++--- main.go | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/http.go b/http.go index 6438306..db6b9e8 100644 --- a/http.go +++ b/http.go @@ -1,7 +1,6 @@ package main import ( - "log" "net/http" "path" "strings" @@ -23,7 +22,7 @@ func ShiftPath(p string) (head, tail string) { return p[1:i], p[i:] } -func ServeWebInterface(listenAddr string, webInterface http.Handler, staticFiles http.FileSystem) { +func ServeWebInterface(listenAddr string, webInterface http.Handler, staticFiles http.FileSystem) error { router := http.NewServeMux() router.Handle("/js/", http.FileServer(staticFiles)) router.Handle("/css/", http.FileServer(staticFiles)) @@ -33,5 +32,5 @@ func ServeWebInterface(listenAddr string, webInterface http.Handler, staticFiles Addr: listenAddr, Handler: router, } - log.Fatal(server.ListenAndServe()) + return server.ListenAndServe() } diff --git a/main.go b/main.go index 79fb6c8..1d39a40 100644 --- a/main.go +++ b/main.go @@ -297,5 +297,9 @@ func main() { initLogFile() go photoBot.Process() - ServeWebInterface(viper.GetString("WebInterface.Listen"), securityFrontend, statikFS) + + err = ServeWebInterface(viper.GetString("WebInterface.Listen"), securityFrontend, statikFS) + if err != nil { + panic(err) + } }