|
|
|
@ -11,8 +11,20 @@ import (
|
|
|
|
|
"strings"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type WsConfOption func(conf config.WSServerConf)
|
|
|
|
|
|
|
|
|
|
func WithWSCheckOrigin(fn func(*http.Request) bool) WsConfOption {
|
|
|
|
|
return func(conf config.WSServerConf) {
|
|
|
|
|
conf.CheckOrigin = fn
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ListenWebsocket 开始监听Websocket
|
|
|
|
|
func (ngin *Engine) ListenWebsocket(conf config.WSServerConf) error {
|
|
|
|
|
func (ngin *Engine) ListenWebsocket(conf config.WSServerConf, opts ...WsConfOption) error {
|
|
|
|
|
for _, opt := range opts {
|
|
|
|
|
opt(conf)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
err := ngin.setup()
|
|
|
|
|
if err != nil {
|
|
|
|
|
nlog.Errorf("%s failed to setup server, err:%v", ngin.LogPrefix(), err)
|
|
|
|
|