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:
|
rove-server:
|
||||||
build: .
|
build: .
|
||||||
ports:
|
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")
|
var port = flag.Int("port", 8080, "The port to host on")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
s := server.NewServer(
|
s := server.NewServer(
|
||||||
server.OptionPort(*port),
|
server.OptionPort(*port),
|
||||||
server.OptionPersistentData())
|
server.OptionPersistentData())
|
||||||
|
|
|
@ -65,7 +65,6 @@ func NewServer(opts ...ServerOption) *Server {
|
||||||
world: game.NewWorld(),
|
world: game.NewWorld(),
|
||||||
persistence: EphemeralData,
|
persistence: EphemeralData,
|
||||||
router: router,
|
router: router,
|
||||||
server: &http.Server{Addr: ":8080", Handler: router},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply all options
|
// Apply all options
|
||||||
|
@ -73,6 +72,9 @@ func NewServer(opts ...ServerOption) *Server {
|
||||||
o(s)
|
o(s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up the server object
|
||||||
|
s.server = &http.Server{Addr: fmt.Sprintf(":%d", s.port), Handler: router}
|
||||||
|
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +106,7 @@ func (s *Server) Run() {
|
||||||
defer s.sync.Done()
|
defer s.sync.Done()
|
||||||
|
|
||||||
// Listen and serve the http requests
|
// 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 {
|
if err := s.server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue