-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
68 lines (51 loc) · 1.12 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
60
61
62
63
64
65
66
67
68
package main
import (
"flag"
"log"
"net/http"
"os"
"text/template"
_ "net/http/pprof"
"github.com/ghthor/aodd/game"
)
var indexTmpl = template.Must(template.New("index.tmpl").ParseFiles("www/index.tmpl"))
func serverUrl(onHeroku bool, domain, port string) string {
url := "http://" + domain
if !onHeroku {
url += ":" + port
}
return url
}
func main() {
domain := os.Getenv("DOMAIN")
port := os.Getenv("PORT")
isHeroku := flag.Bool("heroku", true, "enable is the app is running on heroku")
flag.Parse()
c := game.ShardConfig{
OnHeroku: *isHeroku,
Domain: domain,
Port: port,
JsDir: "www/js",
AssetDir: "www/asset",
CssDir: "www/css",
JsMain: "js/init",
IndexTmpl: indexTmpl,
Mux: http.NewServeMux(),
}
s, err := game.NewSimShard(c)
if err != nil {
log.Fatal(err)
}
go func() {
log.Println("starting profiling server at", "http://localhost:6060")
err := http.ListenAndServe("localhost:6060", nil)
if err != nil {
log.Fatal(err)
}
}()
log.Println("starting server at", serverUrl(*isHeroku, domain, port))
err = s.ListenAndServe()
if err != nil {
log.Fatal(err)
}
}