初始化斗地主残局版项目

This commit is contained in:
wtz
2026-02-19 21:18:12 +08:00
commit 13d2b0e1dc
18 changed files with 2259 additions and 0 deletions

39
app/cmd/main.go Normal file
View File

@@ -0,0 +1,39 @@
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)
}
}