diff --git a/cmd/server/main.go b/cmd/server/main.go index e0fc562..8f33468 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -5,5 +5,5 @@ import "git.saintnet.tech/stryan/snengame/internal/coordinator" func main() { c := coordinator.NewCoordinator() c.Start() - coordinator.Serve(c) + Serve(c) } diff --git a/internal/coordinator/server.go b/cmd/server/server.go similarity index 76% rename from internal/coordinator/server.go rename to cmd/server/server.go index 5bcea60..e5d3b36 100644 --- a/internal/coordinator/server.go +++ b/cmd/server/server.go @@ -1,15 +1,16 @@ -package coordinator +package main import ( "log" "net/http" + "git.saintnet.tech/stryan/snengame/internal/coordinator" "github.com/gorilla/websocket" ) var upgrader = websocket.Upgrader{} // use default options -func Serve(c *Coordinator) { +func Serve(c *coordinator.Coordinator) { http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { serveWs(c, w, r) }) @@ -19,7 +20,7 @@ func Serve(c *Coordinator) { } } -func serveWs(c *Coordinator, w http.ResponseWriter, r *http.Request) { +func serveWs(c *coordinator.Coordinator, w http.ResponseWriter, r *http.Request) { // Upgrade our raw HTTP connection to a websocket based one conn, err := upgrader.Upgrade(w, r, nil) if err != nil { @@ -30,7 +31,7 @@ func serveWs(c *Coordinator, w http.ResponseWriter, r *http.Request) { // The event loop for { - var cmd SessionCommand + var cmd coordinator.SessionCommand err := conn.ReadJSON(&cmd) if err != nil { log.Println("Error during message reading:", err) @@ -47,7 +48,7 @@ func serveWs(c *Coordinator, w http.ResponseWriter, r *http.Request) { log.Println("Error during message writing:", err) break } - if resp.Result == SessionRespLeft { + if resp.Result == coordinator.SessionRespLeft { break } }