5
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2024-12-05 03:15:32 +00:00
matterbridge/vendor/github.com/gorilla/websocket/examples/chat/main.go

41 lines
844 B
Go
Raw Normal View History

2016-04-10 21:39:38 +00:00
// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
// 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"
)
var addr = flag.String("addr", ":8080", "http service address")
func serveHome(w http.ResponseWriter, r *http.Request) {
2017-03-25 19:45:10 +00:00
log.Println(r.URL)
2016-04-10 21:39:38 +00:00
if r.URL.Path != "/" {
http.Error(w, "Not found", 404)
return
}
if r.Method != "GET" {
http.Error(w, "Method not allowed", 405)
return
}
2017-03-25 19:45:10 +00:00
http.ServeFile(w, r, "home.html")
2016-04-10 21:39:38 +00:00
}
func main() {
flag.Parse()
2017-03-25 19:45:10 +00:00
hub := newHub()
go hub.run()
2016-04-10 21:39:38 +00:00
http.HandleFunc("/", serveHome)
2017-03-25 19:45:10 +00:00
http.HandleFunc("/ws", func(w http.ResponseWriter, r *http.Request) {
serveWs(hub, w, r)
})
2016-04-10 21:39:38 +00:00
err := http.ListenAndServe(*addr, nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}