main.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package main
  2. import (
  3. "battlecamp-go-server/board"
  4. "log"
  5. "net/http"
  6. "runtime"
  7. "github.com/julienschmidt/httprouter"
  8. )
  9. func main() {
  10. runtime.GOMAXPROCS(runtime.NumCPU())
  11. router := httprouter.New()
  12. router.GET("/", index)
  13. router.GET("/games/", gameListHandler)
  14. router.GET("/games/:id", gameHandler)
  15. router.PUT("/games", createGameHandler)
  16. router.PUT("/games/:rows/:cols", createGameHandler)
  17. router.POST("/games/:id/move/:playerId/:direction", moveHandler)
  18. // TODO: /games/{id}/players/{playerId}
  19. log.Fatal(http.ListenAndServe(":8080", router))
  20. }
  21. func index(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
  22. w.Write([]byte("Go battlecamp!"))
  23. }
  24. func gameListHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
  25. http.Error(w, "Not implemented", http.StatusNotImplemented)
  26. }
  27. func gameHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
  28. http.Error(w, "Not implemented", http.StatusNotImplemented)
  29. }
  30. func createGameHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
  31. http.Error(w, "Not implemented", http.StatusNotImplemented)
  32. }
  33. func moveHandler(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
  34. http.Error(w, "Not implemented", http.StatusNotImplemented)
  35. }
  36. func boardHandler(w http.ResponseWriter, req *http.Request) {
  37. b := board.New(56, 35)
  38. w.Header().Set("Content-Type", "text/plain;charset=utf-8")
  39. b.WriteJSON(w)
  40. }