2014-04-19 01:25:11 +04:00
|
|
|
// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
|
2013-10-16 20:41:47 +04:00
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"log"
|
|
|
|
"net/http"
|
|
|
|
"text/template"
|
|
|
|
)
|
|
|
|
|
|
|
|
var addr = flag.String("addr", ":8080", "http service address")
|
2016-05-18 17:56:16 +03:00
|
|
|
var homeTemplate = template.Must(template.ParseFiles("home.html"))
|
2013-10-16 20:41:47 +04:00
|
|
|
|
|
|
|
func serveHome(w http.ResponseWriter, r *http.Request) {
|
|
|
|
if r.URL.Path != "/" {
|
|
|
|
http.Error(w, "Not found", 404)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if r.Method != "GET" {
|
2014-06-28 00:08:22 +04:00
|
|
|
http.Error(w, "Method not allowed", 405)
|
2013-10-16 20:41:47 +04:00
|
|
|
return
|
|
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
2016-05-18 17:56:16 +03:00
|
|
|
homeTemplate.Execute(w, r.Host)
|
2013-10-16 20:41:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
flag.Parse()
|
2016-05-27 07:00:24 +03:00
|
|
|
go hub.run()
|
2013-10-16 20:41:47 +04:00
|
|
|
http.HandleFunc("/", serveHome)
|
|
|
|
http.HandleFunc("/ws", serveWs)
|
|
|
|
err := http.ListenAndServe(*addr, nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("ListenAndServe: ", err)
|
|
|
|
}
|
|
|
|
}
|