forked from vortec/orchestrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ws_server.go
37 lines (32 loc) · 819 Bytes
/
ws_server.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
package main
// WebSocket Server
//
// Acts as a hub for WSConnections after you called Run().
// Contains a map of active connections and provides two channels,
// one for registering and one for unregistering WSConnections.
type WSServer struct {
connections map[*WSConnection] bool
register chan *WSConnection
unregister chan *WSConnection
}
// Start waiting for register or unregister commands
func (wss *WSServer) Run() {
for {
select {
case wsc := <- wss.register:
wss.connections[wsc] = true
case wsc := <- wss.unregister:
delete(wss.connections, wsc)
}
}
}
// Fake singleton
var wss = WSServer {
connections: make(map[*WSConnection] bool),
register: make(chan *WSConnection),
unregister: make(chan *WSConnection),
}
// Wrapper function for wss.Run
func runWSServer() {
wss.Run()
}