-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathmain.go
59 lines (46 loc) · 1.27 KB
/
main.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
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"fmt"
"net/http"
"os"
)
func routeRequest(w http.ResponseWriter, r *http.Request) {
// Ignore favicon for sanity
if r.URL.Path == "favicon.ico" {
return
}
// Log Request
fmt.Printf("%s %s\n", r.Method, r.URL)
// Route
switch {
case r.URL.Path == "/" && r.Method == "GET":
fmt.Fprintf(w, "<a href=\"http://github.com/sendwithus/battlesnake-go\">battlesnake-go</a>")
return
case r.URL.Path == "/start" && r.Method == "POST":
handleStart(w, r)
return
case r.URL.Path == "/move" && r.Method == "POST":
handleMove(w, r)
return
case r.URL.Path == "/end" && r.Method == "POST":
handleEnd(w, r)
return
}
// Method not allowed
w.WriteHeader(http.StatusNotFound)
fmt.Fprint(w, "404 Not Found")
}
func main() {
// just cause
http.HandleFunc("/", routeRequest)
// http.HandleFunc("/favicon.ico", handleNothing)
// http.HandleFunc("/start", handleStart)
// http.HandleFunc("/move", handleMove)
// http.HandleFunc("/end", handleEnd)
port := os.Getenv("PORT")
if len(port) == 0 {
port = "9000"
}
fmt.Printf("Running server on port %s...\n", port)
http.ListenAndServe(":" + port, nil)
}