-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
47 lines (37 loc) · 1.02 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
package main
import (
"log"
"net/http"
"os"
"github.com/otonnesen/battlesnake2020/api"
"github.com/otonnesen/battlesnake2020/util"
)
var startResp = api.StartResponse{Color: "#75CEDD", SecondaryColor: "#7A75DD"}
type LogFile struct {
logger *log.Logger
file *os.File
}
var movelog map[string]LogFile
var logging bool // Turns on logging JSON move data for replaying games
func main() {
args := os.Args[1:]
if len(args) > 0 {
// Who needs argparse anyway
if args[0] == "log" {
movelog = make(map[string]LogFile)
log.Printf("Logging enabled")
logging = true
}
}
port := os.Getenv("PORT") // Get Heroku port (or non-Heroku port, I guess)
if port == "" {
log.Printf("$PORT not set, defaulting to 8080")
port = "8080"
}
http.HandleFunc("/start", util.LogRequest(start))
http.HandleFunc("/move", util.LogRequest(move))
http.HandleFunc("/end", util.LogRequest(end))
http.HandleFunc("/ping", util.LogRequest(ping))
log.Printf("Server running on port %s\n", port)
http.ListenAndServe(":"+port, nil)
}