/
main.go
38 lines (28 loc) · 914 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"flag"
"log"
"net/http"
)
//go:generate go get github.com/elazarl/go-bindata-assetfs/... github.com/jteeuwen/go-bindata/...
//go:generate go-bindata-assetfs www/...
var (
// create a flag `-laddr` to bind a given local bind address
laddr = flag.String("laddr", ":8080", "local bind address")
)
func main() {
flag.Parse() // parse flags given by the cli
// create and start a new hub manager
h := NewHub()
go h.Start()
handler := &http.ServeMux{}
// create an http handler for the Chatterbox website created and handled by bindata
handler.Handle("/", http.FileServer(assetFS()))
handler.Handle("/chat", FromHTTP(h)) // handle websocket connections at ws://host/chat
server := http.Server{
Handler: handler,
Addr: *laddr,
}
log.Println("Serving http on:", *laddr)
server.ListenAndServe() // blocking call to create a server socket and accept new connections
}