diff options
Diffstat (limited to 'vendor/github.com/gorilla/websocket/examples/chat/main.go')
-rw-r--r-- | vendor/github.com/gorilla/websocket/examples/chat/main.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/vendor/github.com/gorilla/websocket/examples/chat/main.go b/vendor/github.com/gorilla/websocket/examples/chat/main.go index 3c4448d72..a865ffec5 100644 --- a/vendor/github.com/gorilla/websocket/examples/chat/main.go +++ b/vendor/github.com/gorilla/websocket/examples/chat/main.go @@ -12,9 +12,10 @@ import ( ) var addr = flag.String("addr", ":8080", "http service address") -var homeTempl = template.Must(template.ParseFiles("home.html")) +var homeTemplate = template.Must(template.ParseFiles("home.html")) func serveHome(w http.ResponseWriter, r *http.Request) { + log.Println(r.URL) if r.URL.Path != "/" { http.Error(w, "Not found", 404) return @@ -24,14 +25,17 @@ func serveHome(w http.ResponseWriter, r *http.Request) { return } w.Header().Set("Content-Type", "text/html; charset=utf-8") - homeTempl.Execute(w, r.Host) + homeTemplate.Execute(w, r.Host) } func main() { flag.Parse() - go h.run() + hub := newHub() + go hub.run() http.HandleFunc("/", serveHome) - http.HandleFunc("/ws", serveWs) + http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) { + serveWs(hub, w, r) + }) err := http.ListenAndServe(*addr, nil) if err != nil { log.Fatal("ListenAndServe: ", err) |