simple-web-game/main.go

32 lines
623 B
Go
Raw Normal View History

2013-06-16 00:00:25 -07:00
package main
import (
"flag"
"fmt"
"log"
"net/http"
2014-11-25 00:07:16 -08:00
"golang.org/x/net/websocket"
2013-06-16 00:00:25 -07:00
)
var addr = flag.String("addr", ":8666", "http service address")
var static_files = flag.String("static", "./static", "location of static files")
func main() {
flag.Parse()
http.Handle("/", http.FileServer(http.Dir(
fmt.Sprintf("%s/html", *static_files))))
http.Handle("/static/", http.StripPrefix("/static/",
http.FileServer(http.Dir(*static_files))))
http.Handle("/ws/game/", websocket.Handler(addPlayer))
go g.run()
err := http.ListenAndServe(*addr, nil)
if err != nil {
log.Fatal("unable to start server")
}
}