forked from fxaa/codenames.plus
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
47 lines (39 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 (
"flag"
"fmt"
"net/http"
"os"
"github.com/markbates/pkger"
"github.com/sirupsen/logrus"
)
var (
listenAll = flag.Bool("all", false, "listen to any address or just localhost. localhost by default")
portFlag = flag.Int("port", 8080, "server port")
)
var log = logrus.New()
func main() {
flag.Parse()
log.Out = os.Stdout
pkger.Include("/server")
pkger.Include("/public")
server := socketServer(NewActionRouter())
go func() {
if err := server.Serve(); err != nil {
log.Fatalf("socketio listen error: %s\n", err)
}
}()
defer server.Close()
http.Handle("/socket.io/", server)
http.HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) {
// original API pinged, keep it?
w.WriteHeader(http.StatusOK)
})
http.Handle("/", http.FileServer(pkger.Dir("/public")))
addr := fmt.Sprintf("localhost:%d", *portFlag)
if *listenAll {
addr = fmt.Sprintf(":%d", *portFlag)
}
fmt.Printf("Listening on http://%s\n", addr)
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", *portFlag), nil))
}