-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.go
52 lines (41 loc) · 906 Bytes
/
app.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"log"
"net/http"
"time"
"github.com/gorilla/websocket"
)
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool { return true },
}
const (
// Time allowed to write a message to the peer.
writeWait = 10 * time.Second
// Time allowed to read the next pong message from the peer.
pongWait = 60 * time.Second
// Send pings to peer with this period. Must be less than pongWait.
pingPeriod = (pongWait * 9) / 10
// Maximum message size allowed from peer.
maxMessageSize = 512
)
var (
newline = []byte{'\n'}
space = []byte{' '}
)
type App struct {
Hubs map[string]*Hub
}
func runApp() *App {
return &App{
Hubs: make(map[string]*Hub),
}
}
func (a *App) RegHub(id string) (hub *Hub) {
log.Println("Registered new Hub: ", id)
hub = newHub()
go hub.run()
a.Hubs[id] = hub
return hub
}