forked from poiriermike/battlesnake-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathroutes.go
47 lines (38 loc) · 995 Bytes
/
routes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"log"
"net/http"
"github.com/battlesnakeio/starter-snake-go/api"
)
func Index(res http.ResponseWriter, req *http.Request) {
res.WriteHeader(http.StatusOK)
res.Write([]byte("Battlesnake documentation can be found at <a href=\"https://docs.battlesnake.io\">https://docs.battlesnake.io</a>."))
}
func Start(res http.ResponseWriter, req *http.Request) {
decoded := api.SnakeRequest{}
err := api.DecodeSnakeRequest(req, &decoded)
if err != nil {
log.Printf("Bad start request: %v", err)
}
dump(decoded)
respond(res, api.StartResponse{
Color: "#75CEDD",
})
}
func Move(res http.ResponseWriter, req *http.Request) {
decoded := api.SnakeRequest{}
err := api.DecodeSnakeRequest(req, &decoded)
if err != nil {
log.Printf("Bad move request: %v", err)
}
dump(decoded)
respond(res, api.MoveResponse{
Move: "down",
})
}
func End(res http.ResponseWriter, req *http.Request) {
return
}
func Ping(res http.ResponseWriter, req *http.Request) {
return
}