main.go 478 B

123456789101112131415161718192021222324
  1. package main
  2. import (
  3. "runtime"
  4. "log"
  5. "net/http"
  6. "pinguin/board"
  7. )
  8. func main() {
  9. runtime.GOMAXPROCS(1)
  10. http.HandleFunc("/api/board", boardHandler)
  11. http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  12. w.Write([]byte("Go battlecamp!"))
  13. })
  14. log.Fatal(http.ListenAndServe(":8080", nil))
  15. }
  16. func boardHandler(w http.ResponseWriter, req *http.Request) {
  17. b := board.New(56, 35)
  18. w.Header().Set("Content-Type", "text/plain;charset=utf-8")
  19. b.WriteJSON(w)
  20. }