-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweb.go
44 lines (36 loc) · 898 Bytes
/
web.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
package main
import (
"victorz.ca/gameserv/duel"
"victorz.ca/gameserv/slime"
"fmt"
"net/http"
"os"
)
var slimeServer = slime.NewServer()
var duelGame = duel.NewServer()
func init() {
http.HandleFunc("/s/n", slimeServer.HandleNum)
http.HandleFunc("/s", slimeServer.HandlePlayer)
http.HandleFunc("/d/n", duelGame.HandleNum)
http.HandleFunc("/d", duelGame.HandlePlayer)
http.HandleFunc("/", hello)
}
func hello(res http.ResponseWriter, req *http.Request) {
fmt.Fprintf(res, "hello")
}
// Entry point of server program
func main() {
// go slimeServer.Run()
go duelGame.Run()
bind := ":8080"
if env := os.Getenv("OPENSHIFT_GO_PORT"); env != "" {
bind = os.Getenv("OPENSHIFT_GO_IP") + ":" + env
} else if env := os.Getenv("PORT"); env != "" {
bind = ":" + env
}
fmt.Printf("Listening on %s\n", bind)
err := http.ListenAndServe(bind, nil)
if err != nil {
panic(err)
}
}