Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Fix logging of where application is bound
Browse files Browse the repository at this point in the history
  • Loading branch information
hut8 committed May 1, 2022
1 parent 11507d3 commit 45e789e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
7 changes: 3 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ import (
func (a *App) Serve(srvs ...servers.Server) error {
var wg sync.WaitGroup

// FIXME: this information is not correct.
// It needs to be fixed as we support multiple servers.
a.Logger.Infof("starting application at http://%s", a.Options.Addr)

payload := events.Payload{
"app": a,
}
Expand All @@ -35,6 +31,7 @@ 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:])
Expand Down Expand Up @@ -98,6 +95,8 @@ 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())
wg.Add(1)
go func(s servers.Server) {
defer wg.Done()
Expand Down
5 changes: 5 additions & 0 deletions servers/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func (s *Listener) SetAddr(addr string) {
}
}

// Addr gets the HTTP server address
func (s *Listener) Addr() string {
return s.Server.Addr
}

// Start the server
func (s *Listener) Start(c context.Context, h http.Handler) error {
s.Handler = h
Expand Down
1 change: 1 addition & 0 deletions servers/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

// Server allows for custom server implementations
type Server interface {
Addr() string
Shutdown(context.Context) error
Start(context.Context, http.Handler) error
SetAddr(string)
Expand Down
5 changes: 5 additions & 0 deletions servers/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ func (s *Simple) SetAddr(addr string) {
}
}

// Addr gets the HTTP server address
func (s *Simple) Addr() string {
return s.Server.Addr
}

// Start the server
func (s *Simple) Start(c context.Context, h http.Handler) error {
s.Handler = h
Expand Down
5 changes: 5 additions & 0 deletions servers/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ func (s *TLS) SetAddr(addr string) {
}
}

// Addr gets the HTTP server address
func (s *TLS) Addr() string {
return s.Server.Addr
}

// Start the server
func (s *TLS) Start(c context.Context, h http.Handler) error {
s.Handler = h
Expand Down

0 comments on commit 45e789e

Please sign in to comment.