|
|
@@ -1,20 +1,47 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
+ "battlecamp-go-server/board"
|
|
|
"log"
|
|
|
"net/http"
|
|
|
- "battlecamp-go-server/board"
|
|
|
"runtime"
|
|
|
+
|
|
|
+ "github.com/julienschmidt/httprouter"
|
|
|
)
|
|
|
|
|
|
func main() {
|
|
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
|
|
- http.HandleFunc("/api/board", boardHandler)
|
|
|
- http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
|
|
- w.Write([]byte("Go battlecamp!"))
|
|
|
- })
|
|
|
|
|
|
- log.Fatal(http.ListenAndServe(":8080", nil))
|
|
|
+ router := httprouter.New()
|
|
|
+ router.GET("/", index)
|
|
|
+ router.GET("/games/", gameListHandler)
|
|
|
+ router.GET("/games/:id", gameHandler)
|
|
|
+ router.PUT("/games", createGameHandler)
|
|
|
+ router.PUT("/games/:rows/:cols", createGameHandler)
|
|
|
+ router.POST("/games/:id/move/:playerId/:direction", moveHandler)
|
|
|
+ // TODO: /games/{id}/players/{playerId}
|
|
|
+
|
|
|
+ log.Fatal(http.ListenAndServe(":8080", router))
|
|
|
+}
|
|
|
+
|
|
|
+func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
+ w.Write([]byte("Go battlecamp!"))
|
|
|
+}
|
|
|
+
|
|
|
+func gameListHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
|
|
|
+ http.Error(w, "Not implemented", http.StatusNotImplemented)
|
|
|
+}
|
|
|
+
|
|
|
+func gameHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
+ http.Error(w, "Not implemented", http.StatusNotImplemented)
|
|
|
+}
|
|
|
+
|
|
|
+func createGameHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
+ http.Error(w, "Not implemented", http.StatusNotImplemented)
|
|
|
+}
|
|
|
+
|
|
|
+func moveHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
|
|
+ http.Error(w, "Not implemented", http.StatusNotImplemented)
|
|
|
}
|
|
|
|
|
|
func boardHandler(w http.ResponseWriter, req *http.Request) {
|