|
@@ -28,6 +28,10 @@ func main() {
|
|
|
// TODO: /games/{id}/players/{playerId}
|
|
// TODO: /games/{id}/players/{playerId}
|
|
|
router.POST("/games/:gameid/move/:playerId/:direction", movePlayer)
|
|
router.POST("/games/:gameid/move/:playerId/:direction", movePlayer)
|
|
|
|
|
|
|
|
|
|
+ router.PanicHandler = func(w http.ResponseWriter, r *http.Request, something interface{}) {
|
|
|
|
|
+ http.Error(w, "Internal server error", http.StatusInternalServerError)
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
log.Fatal(http.ListenAndServe(":8080", router))
|
|
log.Fatal(http.ListenAndServe(":8080", router))
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -97,23 +101,21 @@ func showBoard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
|
|
yString := req.FormValue("y")
|
|
yString := req.FormValue("y")
|
|
|
colsString := req.FormValue("cols")
|
|
colsString := req.FormValue("cols")
|
|
|
rowsString := req.FormValue("rows")
|
|
rowsString := req.FormValue("rows")
|
|
|
- var x, y, cols, rows int
|
|
|
|
|
-
|
|
|
|
|
- if xString != "" && yString != "" && colsString != "" && rowsString != "" {
|
|
|
|
|
- x, _ = strconv.Atoi(xString)
|
|
|
|
|
- y, _ = strconv.Atoi(yString)
|
|
|
|
|
- cols, _ = strconv.Atoi(colsString)
|
|
|
|
|
- rows, _ = strconv.Atoi(rowsString)
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- log.Printf("%v %v %v %v", x, y, cols, rows)
|
|
|
|
|
|
|
+
|
|
|
id, _ := strconv.ParseInt(ps.ByName("boardid"), 10, 64)
|
|
id, _ := strconv.ParseInt(ps.ByName("boardid"), 10, 64)
|
|
|
b := currentGames.GetGame(id).Board
|
|
b := currentGames.GetGame(id).Board
|
|
|
- b.WriteJSON(w)
|
|
|
|
|
- //x, _ := strconv.Atoi()
|
|
|
|
|
- //y, _ := strconv.Atoi(req.FormValue("y"))
|
|
|
|
|
- //rows, _ := strconv.Atoi(req.FormValue("rows"))
|
|
|
|
|
- //cols, _ := strconv.Atoi(req.FormValue("cols"))
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if xString != "" && yString != "" && colsString != "" && rowsString != "" {
|
|
|
|
|
+ x, _ := strconv.Atoi(xString)
|
|
|
|
|
+ y, _ := strconv.Atoi(yString)
|
|
|
|
|
+ cols, _ := strconv.Atoi(colsString)
|
|
|
|
|
+ rows, _ := strconv.Atoi(rowsString)
|
|
|
|
|
+ b.WriteJSON(w, x, y, cols, rows)
|
|
|
|
|
+ } else if xString != "" || yString != "" || colsString != "" || rowsString != "" {
|
|
|
|
|
+ http.Error(w, "Bad request", http.StatusBadRequest)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ b.WriteJSON(w, 0, 0, b.Cols, b.Rows)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func showAsciiBoard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
|
func showAsciiBoard(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|