40 lines
804 B
Go
40 lines
804 B
Go
package main
|
|
|
|
import (
|
|
"doudizhu-server/internal/game"
|
|
"doudizhu-server/internal/handlers"
|
|
"doudizhu-server/internal/ws"
|
|
"log"
|
|
"net/http"
|
|
)
|
|
|
|
func main() {
|
|
gameMgr := game.NewGameManager()
|
|
hub := ws.NewHub(gameMgr)
|
|
go hub.Run()
|
|
|
|
h := handlers.NewHandler(gameMgr, hub)
|
|
|
|
mux := http.NewServeMux()
|
|
mux.HandleFunc("/api/rooms", func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method == "POST" {
|
|
h.CreateRoom(w, r)
|
|
} else {
|
|
http.NotFound(w, r)
|
|
}
|
|
})
|
|
mux.HandleFunc("/api/rooms/", func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Method == "POST" {
|
|
h.JoinRoom(w, r)
|
|
} else {
|
|
http.NotFound(w, r)
|
|
}
|
|
})
|
|
mux.HandleFunc("/api/ws", h.WebSocket)
|
|
|
|
log.Println("App server starting on :8080")
|
|
if err := http.ListenAndServe(":8080", mux); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|