Fix passing port on command line

This commit is contained in:
Marc Di Luzio 2020-06-01 18:10:25 +01:00
parent 2e7b2d2928
commit 07c5b9cf5a
3 changed files with 8 additions and 3 deletions

View file

@ -65,7 +65,6 @@ func NewServer(opts ...ServerOption) *Server {
world: game.NewWorld(),
persistence: EphemeralData,
router: router,
server: &http.Server{Addr: ":8080", Handler: router},
}
// Apply all options
@ -73,6 +72,9 @@ func NewServer(opts ...ServerOption) *Server {
o(s)
}
// Set up the server object
s.server = &http.Server{Addr: fmt.Sprintf(":%d", s.port), Handler: router}
return s
}
@ -104,7 +106,7 @@ func (s *Server) Run() {
defer s.sync.Done()
// Listen and serve the http requests
fmt.Println("Serving HTTP")
fmt.Printf("Serving HTTP on port %d\n", s.port)
if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
log.Fatal(err)
}