-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsconn.go
71 lines (59 loc) · 1.52 KB
/
wsconn.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package wsconn
import (
"net/http"
"github.com/gorilla/websocket"
"github.com/sivaosorg/govm/logger"
"github.com/sivaosorg/govm/utils"
"github.com/sivaosorg/govm/wsconnx"
)
var (
_logger = logger.NewLogger()
conf = wsconnx.GetWsConnOptionConfigSample()
wsUpgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
return true
},
}
)
func NewWebsocket() *Websocket {
w := &Websocket{}
w.SetBroadcast(make(map[string]chan wsconnx.WsConnMessagePayload))
w.SetSubscribers(make(map[*websocket.Conn]wsconnx.WsConnSubscription))
w.SetOption(*conf)
w.SetUpgrader(wsUpgrader)
w.SetEnabledClosure(false)
w.SetTopics(make(map[string]bool))
return w
}
func (w *Websocket) SetBroadcast(value map[string]chan wsconnx.WsConnMessagePayload) *Websocket {
w.broadcast = value
return w
}
func (w *Websocket) SetSubscribers(value map[*websocket.Conn]wsconnx.WsConnSubscription) *Websocket {
w.subscribers = value
return w
}
func (w *Websocket) SetOption(value wsconnx.WsConnOptionConfig) *Websocket {
w.Option = value
return w
}
func (w *Websocket) SetUpgrader(value websocket.Upgrader) *Websocket {
w.upgrader = value
return w
}
func (w *Websocket) Upgrader() websocket.Upgrader {
return w.upgrader
}
func (w *Websocket) SetEnabledClosure(value bool) *Websocket {
w.IsEnabledClosure = value
return w
}
func (w *Websocket) SetTopics(value map[string]bool) *Websocket {
w.Topics = value
return w
}
func (w *Websocket) Json() string {
return utils.ToJson(w)
}