Esempio n. 1
0
func serveIndex(w http.ResponseWriter, r *http.Request) {
	// check for and process static file requests
	matches := static_regex.FindStringSubmatch(r.URL.Path)
	if len(matches) > 0 {
		static_http.ServeHTTP(w, r)
		logger.Debugf("Static fetch for resource: %s", r.URL.Path)
	} else {
		// return the index.html
		t, err := template.ParseFiles("index.html")
		if err != nil {
			panic(err)
		}
		t.Execute(w, "")
		logger.Debug("Fetch for home page")
	}
}
Esempio n. 2
0
func Main() {
	logger.SetupLogger(logger.DEBUG, logger.USUAL)
	setupGamehub()

	go gamehub.handleConnections()

	static_http.Handle("/", http.FileServer(http.Dir("./")))

	http.HandleFunc("/", serveIndex)
	http.HandleFunc("/ws", serveWs)

	logger.Debug("Http server listening on port 8888")
	err := http.ListenAndServe(":8888", nil)
	if err != nil {
		logger.Fatalf("ListenAndServe: %s", err.Error())
	}
}