初始化斗地主残局版项目
This commit is contained in:
39
app/cmd/main.go
Normal file
39
app/cmd/main.go
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user