ing
This commit is contained in:
parent
af27365039
commit
a5e92f2b11
|
@ -152,11 +152,7 @@ func NewSocket(sb SocketBuilder, parentContext cuc.Context) (Socket, error) {
|
||||||
logging.Logger().Panic("Client Socket: SocketContext must be specified")
|
logging.Logger().Panic("Client Socket: SocketContext must be specified")
|
||||||
}
|
}
|
||||||
|
|
||||||
sh := sb.SocketHandler()
|
sh := sb.GetSocketHandler()
|
||||||
if nil == sh {
|
|
||||||
logging.Logger().Panic("Client Socket: SocketHandler must be specified")
|
|
||||||
}
|
|
||||||
sh.Validate()
|
|
||||||
|
|
||||||
d := &websocket.Dialer{}
|
d := &websocket.Dialer{}
|
||||||
d.NetDial = sb.Dial
|
d.NetDial = sb.Dial
|
||||||
|
|
|
@ -12,8 +12,8 @@ import (
|
||||||
|
|
||||||
type SocketBuilder interface {
|
type SocketBuilder interface {
|
||||||
SocketContext(parent cuc.Context) SocketContext
|
SocketContext(parent cuc.Context) SocketContext
|
||||||
SocketHandler() SocketHandler
|
|
||||||
|
|
||||||
|
GetSocketHandler() SocketHandler
|
||||||
GetURL() string
|
GetURL() string
|
||||||
GetRequestCookie() http.CookieJar
|
GetRequestCookie() http.CookieJar
|
||||||
GetRequestHeader() http.Header
|
GetRequestHeader() http.Header
|
||||||
|
|
|
@ -7,11 +7,14 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"git.loafle.net/commons_go/logging"
|
||||||
|
|
||||||
cuc "git.loafle.net/commons_go/util/context"
|
cuc "git.loafle.net/commons_go/util/context"
|
||||||
cwf "git.loafle.net/commons_go/websocket_fasthttp"
|
cwf "git.loafle.net/commons_go/websocket_fasthttp"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SocketBuilders struct {
|
type SocketBuilders struct {
|
||||||
|
SocketHandler SocketHandler
|
||||||
URL string
|
URL string
|
||||||
RequestCookie http.CookieJar
|
RequestCookie http.CookieJar
|
||||||
RequestHeader http.Header
|
RequestHeader http.Header
|
||||||
|
@ -27,10 +30,6 @@ func (sb *SocketBuilders) SocketContext(parent cuc.Context) SocketContext {
|
||||||
return newSocketContext(parent)
|
return newSocketContext(parent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sb *SocketBuilders) SocketHandler() SocketHandler {
|
|
||||||
return NewSocketHandler()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (sb *SocketBuilders) UseProxy(req *http.Request) (*url.URL, error) {
|
func (sb *SocketBuilders) UseProxy(req *http.Request) (*url.URL, error) {
|
||||||
return http.ProxyFromEnvironment(req)
|
return http.ProxyFromEnvironment(req)
|
||||||
}
|
}
|
||||||
|
@ -46,6 +45,10 @@ func (sb *SocketBuilders) Dial(network, addr string) (net.Conn, error) {
|
||||||
return netDialer.Dial(network, addr)
|
return netDialer.Dial(network, addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sb *SocketBuilders) GetSocketHandler() SocketHandler {
|
||||||
|
return sb.SocketHandler
|
||||||
|
}
|
||||||
|
|
||||||
func (sb *SocketBuilders) GetHandshakeTimeout() time.Duration {
|
func (sb *SocketBuilders) GetHandshakeTimeout() time.Duration {
|
||||||
return sb.HandshakeTimeout
|
return sb.HandshakeTimeout
|
||||||
}
|
}
|
||||||
|
@ -83,6 +86,11 @@ func (sb *SocketBuilders) GetWriteBufferSize() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sb *SocketBuilders) Validate() {
|
func (sb *SocketBuilders) Validate() {
|
||||||
|
if nil == sb.SocketHandler {
|
||||||
|
logging.Logger().Panic("Websocket Fasthttp: SocketHandler must be specified")
|
||||||
|
}
|
||||||
|
sb.SocketHandler.Validate()
|
||||||
|
|
||||||
if 0 >= sb.HandshakeTimeout {
|
if 0 >= sb.HandshakeTimeout {
|
||||||
sb.HandshakeTimeout = cwf.DefaultHandshakeTimeout
|
sb.HandshakeTimeout = cwf.DefaultHandshakeTimeout
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user