Refactor into server object to handle registered accounts

This commit is contained in:
Marc Di Luzio 2020-05-31 11:18:26 +01:00
parent eccb726f74
commit 93decc027b
13 changed files with 304 additions and 128 deletions

View file

@ -3,28 +3,21 @@ package main
import (
"flag"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"github.com/mdiluz/rove/pkg/rovegame"
"github.com/mdiluz/rove/pkg/server"
)
var port = flag.Int("port", 8080, "The port to host on")
func main() {
server := server.NewServer(*port)
fmt.Println("Initialising...")
// Set up the world
world := rovegame.NewWorld()
fmt.Printf("World created\n\t%+v\n", world)
// Create a new router
router := NewRouter()
fmt.Printf("Router Created\n")
server.Initialise()
// Set up the close handler
c := make(chan os.Signal)
@ -37,9 +30,5 @@ func main() {
fmt.Println("Initialised")
// Listen and serve the http requests
fmt.Println("Serving HTTP")
if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), router); err != nil {
log.Fatal(err)
}
server.Run()
}