fix: 修复wsConf的func参数问题,添加checkorigin的注入方式。

main v1.1.1
NoahLan 2 years ago
parent 73af4fce09
commit 40860ee0f9

@ -26,7 +26,7 @@ type (
// TLS 证书key地址
TLSKey string `json:",optional"`
// check origin
CheckOrigin func(*http.Request) bool
CheckOrigin func(*http.Request) bool `json:",optional"`
}
)

@ -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)

Loading…
Cancel
Save