Fix passing port on command line
This commit is contained in:
parent
2e7b2d2928
commit
07c5b9cf5a
3 changed files with 8 additions and 3 deletions
|
@ -3,4 +3,5 @@ services:
|
|||
rove-server:
|
||||
build: .
|
||||
ports:
|
||||
- "80:8080"
|
||||
- "80:80"
|
||||
command: ./rove-server --port 80
|
2
main.go
2
main.go
|
@ -13,6 +13,8 @@ import (
|
|||
var port = flag.Int("port", 8080, "The port to host on")
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
s := server.NewServer(
|
||||
server.OptionPort(*port),
|
||||
server.OptionPersistentData())
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue