From 5f675ebc701bc7008b481d7ae5f3dc171fe3a6a6 Mon Sep 17 00:00:00 2001 From: Liam Bowen Date: Tue, 26 Apr 2022 20:03:53 +0000 Subject: [PATCH] Revision as per @sio4 Makes changes backwards compatible and restores logging statement at beginning of startup --- server.go | 6 +++--- servers/listener.go | 7 ++++--- servers/servers.go | 1 - servers/simple.go | 7 ++++--- servers/tls.go | 7 ++++--- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/server.go b/server.go index 26a57e97c..d225904b9 100644 --- a/server.go +++ b/server.go @@ -22,6 +22,8 @@ import ( func (a *App) Serve(srvs ...servers.Server) error { var wg sync.WaitGroup + a.Logger.Debug("starting application") + payload := events.Payload{ "app": a, } @@ -31,7 +33,6 @@ func (a *App) Serve(srvs ...servers.Server) error { return err } - // Add default server if necessary if len(srvs) == 0 { if strings.HasPrefix(a.Options.Addr, "unix:") { tcp, err := servers.UnixSocket(a.Options.Addr[5:]) @@ -95,8 +96,7 @@ func (a *App) Serve(srvs ...servers.Server) error { for _, s := range srvs { s.SetAddr(a.Addr) - a.Logger.Infof("starting server of type %T at %s", - s, s.Addr()) + a.Logger.Infof("starting %s", s) wg.Add(1) go func(s servers.Server) { defer wg.Done() diff --git a/servers/listener.go b/servers/listener.go index 6f3497308..e0f985d76 100644 --- a/servers/listener.go +++ b/servers/listener.go @@ -2,6 +2,7 @@ package servers import ( "context" + "fmt" "net" "net/http" ) @@ -19,9 +20,9 @@ func (s *Listener) SetAddr(addr string) { } } -// Addr gets the HTTP server address -func (s *Listener) Addr() string { - return s.Server.Addr +// String returns a string representation of a Listener +func (s *Listener) String() string { + return fmt.Sprintf("listener on %s", s.Server.Addr) } // Start the server diff --git a/servers/servers.go b/servers/servers.go index 93d1f831d..4a703d74f 100644 --- a/servers/servers.go +++ b/servers/servers.go @@ -8,7 +8,6 @@ import ( // Server allows for custom server implementations type Server interface { - Addr() string Shutdown(context.Context) error Start(context.Context, http.Handler) error SetAddr(string) diff --git a/servers/simple.go b/servers/simple.go index 9b57a99c1..61891e441 100644 --- a/servers/simple.go +++ b/servers/simple.go @@ -2,6 +2,7 @@ package servers import ( "context" + "fmt" "net/http" ) @@ -17,9 +18,9 @@ func (s *Simple) SetAddr(addr string) { } } -// Addr gets the HTTP server address -func (s *Simple) Addr() string { - return s.Server.Addr +// String returns a string representation of a Simple server +func (s *Simple) String() string { + return fmt.Sprintf("simple server on %s", s.Server.Addr) } // Start the server diff --git a/servers/tls.go b/servers/tls.go index 5a48524ae..8e5f837b7 100644 --- a/servers/tls.go +++ b/servers/tls.go @@ -2,6 +2,7 @@ package servers import ( "context" + "fmt" "net/http" ) @@ -19,9 +20,9 @@ func (s *TLS) SetAddr(addr string) { } } -// Addr gets the HTTP server address -func (s *TLS) Addr() string { - return s.Server.Addr +// String returns a string representation of a Listener +func (s *TLS) String() string { + return fmt.Sprintf("TLS server on %s", s.Server.Addr) } // Start the server