From 39c4777fc8ec0b88ccb3f78aab3cb7a391b70def Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferdinand=20M=C3=BCtsch?= Date: Tue, 5 Jan 2021 11:28:51 +0100 Subject: [PATCH] fix: crash on fail to listen --- main.go | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 12c53dc..1ab7792 100644 --- a/main.go +++ b/main.go @@ -210,20 +210,36 @@ func listen(handler http.Handler) { if config.UseTLS() { if s4 != nil { fmt.Printf("Listening for HTTPS on %s.\n", s4.Addr) - go s4.ListenAndServeTLS(config.Server.TlsCertPath, config.Server.TlsKeyPath) + go func() { + if err := s4.ListenAndServeTLS(config.Server.TlsCertPath, config.Server.TlsKeyPath); err != nil { + log.Fatalln(err) + } + }() } if s6 != nil { fmt.Printf("Listening for HTTPS on %s.\n", s6.Addr) - go s6.ListenAndServeTLS(config.Server.TlsCertPath, config.Server.TlsKeyPath) + go func() { + if err := s6.ListenAndServeTLS(config.Server.TlsCertPath, config.Server.TlsKeyPath); err != nil { + log.Fatalln(err) + } + }() } } else { if s4 != nil { fmt.Printf("Listening for HTTP on %s.\n", s4.Addr) - go s4.ListenAndServe() + go func() { + if err := s4.ListenAndServe(); err != nil { + log.Fatalln(err) + } + }() } if s6 != nil { fmt.Printf("Listening for HTTP on %s.\n", s6.Addr) - go s6.ListenAndServe() + go func() { + if err := s6.ListenAndServe(); err != nil { + log.Fatalln(err) + } + }() } }