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

Commit

Permalink
Revision as per @sio4
Browse files Browse the repository at this point in the history
Makes changes backwards compatible and restores logging statement at
beginning of startup
  • Loading branch information
hut8 committed Apr 26, 2022
1 parent b0feb1e commit cb33203
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
6 changes: 3 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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:])
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions servers/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package servers

import (
"context"
"fmt"
"net"
"net/http"
)
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion servers/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions servers/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package servers

import (
"context"
"fmt"
"net/http"
)

Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions servers/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package servers

import (
"context"
"fmt"
"net/http"
)

Expand All @@ -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
Expand Down

0 comments on commit cb33203

Please sign in to comment.