-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (36 loc) · 903 Bytes
/
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
package main
import (
"github.com/rs/cors"
"gomoku/handlers"
"log"
"net/http"
"flag"
"os"
"runtime/pprof"
"time"
)
const PORT = "0.0.0.0:5555"
var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
func main() {
flag.Parse()
if *cpuprofile != "" {
f, err := os.Create(*cpuprofile)
if err != nil {
log.Fatal("could not create CPU profile: ", err)
}
if err := pprof.StartCPUProfile(f); err != nil {
log.Fatal("could not start CPU profile: ", err)
}
go func() {
time.Sleep(time.Second * 30)
pprof.StopCPUProfile()
log.Println("profiling stopped")
}()
}
mux := http.NewServeMux()
mux.HandleFunc("/board", handlers.Board)
mux.HandleFunc("/make-move", handlers.MakeMove)
mux.HandleFunc("/suggest-moves", handlers.SuggestMoves)
println("Starting server at " + PORT)
log.Fatalln(http.ListenAndServe(PORT, cors.Default().Handler(mux)))
}