main.go 887 B

123456789101112131415161718192021222324252627282930
  1. package main
  2. import (
  3. "battlecamp-go-server/board"
  4. "log"
  5. "net/http"
  6. "strconv"
  7. )
  8. func main() {
  9. http.HandleFunc("/", generateBoard)
  10. http.HandleFunc("/status", status)
  11. log.Fatal(http.ListenAndServe(":8081", nil))
  12. }
  13. func generateBoard(w http.ResponseWriter, r *http.Request) {
  14. x, _ := strconv.Atoi(r.FormValue("x"))
  15. y, _ := strconv.Atoi(r.FormValue("y"))
  16. width, _ := strconv.Atoi(r.FormValue("width"))
  17. height, _ := strconv.Atoi(r.FormValue("height"))
  18. totalWidth, _ := strconv.Atoi(r.FormValue("totalWidth"))
  19. totalHeight, _ := strconv.Atoi(r.FormValue("totalHeight"))
  20. log.Printf("Creating partial x=%v, y=%v, width=%v, height=%v, totalWidth=%v, totalHeight=%v", x, y, width, height, totalWidth, totalHeight)
  21. b := board.NewPartial(x, y, width, height, totalWidth, totalHeight)
  22. b.WriteData(w)
  23. }
  24. func status(w http.ResponseWriter, r *http.Request) {
  25. w.Write([]byte("ok"))
  26. }