|
|
@ -11,16 +11,16 @@ import (
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type WsConfOption func(conf config.WSServerConf)
|
|
|
|
type WsConfOption func(conf config.WSServerFullConf)
|
|
|
|
|
|
|
|
|
|
|
|
func WithWSCheckOrigin(fn func(*http.Request) bool) WsConfOption {
|
|
|
|
func WithWSCheckOrigin(fn func(*http.Request) bool) WsConfOption {
|
|
|
|
return func(conf config.WSServerConf) {
|
|
|
|
return func(conf config.WSServerFullConf) {
|
|
|
|
conf.CheckOrigin = fn
|
|
|
|
conf.CheckOrigin = fn
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ListenWebsocket 开始监听Websocket
|
|
|
|
// ListenWebsocket 开始监听Websocket
|
|
|
|
func (ngin *Engine) ListenWebsocket(conf config.WSServerConf, opts ...WsConfOption) error {
|
|
|
|
func (ngin *Engine) ListenWebsocket(conf config.WSServerFullConf, opts ...WsConfOption) error {
|
|
|
|
for _, opt := range opts {
|
|
|
|
for _, opt := range opts {
|
|
|
|
opt(conf)
|
|
|
|
opt(conf)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -51,7 +51,7 @@ func (ngin *Engine) handleWS(conn *websocket.Conn) {
|
|
|
|
ngin.handle(wsConn)
|
|
|
|
ngin.handle(wsConn)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (ngin *Engine) upgradeWebsocket(conf config.WSServerConf) {
|
|
|
|
func (ngin *Engine) upgradeWebsocket(conf config.WSServerFullConf) {
|
|
|
|
upgrade := websocket.Upgrader{
|
|
|
|
upgrade := websocket.Upgrader{
|
|
|
|
HandshakeTimeout: conf.HandshakeTimeout,
|
|
|
|
HandshakeTimeout: conf.HandshakeTimeout,
|
|
|
|
ReadBufferSize: conf.ReadBufferSize,
|
|
|
|
ReadBufferSize: conf.ReadBufferSize,
|
|
|
|