From a5e92f2b1131efb76e1885d1e4f1b678f721b6e5 Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 8 Dec 2017 16:41:43 +0900 Subject: [PATCH] ing --- client/socket.go | 6 +----- client/socket_builder.go | 2 +- client/socket_builders.go | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/client/socket.go b/client/socket.go index ffa52de..515d430 100644 --- a/client/socket.go +++ b/client/socket.go @@ -152,11 +152,7 @@ func NewSocket(sb SocketBuilder, parentContext cuc.Context) (Socket, error) { logging.Logger().Panic("Client Socket: SocketContext must be specified") } - sh := sb.SocketHandler() - if nil == sh { - logging.Logger().Panic("Client Socket: SocketHandler must be specified") - } - sh.Validate() + sh := sb.GetSocketHandler() d := &websocket.Dialer{} d.NetDial = sb.Dial diff --git a/client/socket_builder.go b/client/socket_builder.go index f2426d5..a329167 100644 --- a/client/socket_builder.go +++ b/client/socket_builder.go @@ -12,8 +12,8 @@ import ( type SocketBuilder interface { SocketContext(parent cuc.Context) SocketContext - SocketHandler() SocketHandler + GetSocketHandler() SocketHandler GetURL() string GetRequestCookie() http.CookieJar GetRequestHeader() http.Header diff --git a/client/socket_builders.go b/client/socket_builders.go index 58b245d..20d4c3e 100644 --- a/client/socket_builders.go +++ b/client/socket_builders.go @@ -7,11 +7,14 @@ import ( "net/url" "time" + "git.loafle.net/commons_go/logging" + cuc "git.loafle.net/commons_go/util/context" cwf "git.loafle.net/commons_go/websocket_fasthttp" ) type SocketBuilders struct { + SocketHandler SocketHandler URL string RequestCookie http.CookieJar RequestHeader http.Header @@ -27,10 +30,6 @@ func (sb *SocketBuilders) SocketContext(parent cuc.Context) SocketContext { return newSocketContext(parent) } -func (sb *SocketBuilders) SocketHandler() SocketHandler { - return NewSocketHandler() -} - func (sb *SocketBuilders) UseProxy(req *http.Request) (*url.URL, error) { return http.ProxyFromEnvironment(req) } @@ -46,6 +45,10 @@ func (sb *SocketBuilders) Dial(network, addr string) (net.Conn, error) { return netDialer.Dial(network, addr) } +func (sb *SocketBuilders) GetSocketHandler() SocketHandler { + return sb.SocketHandler +} + func (sb *SocketBuilders) GetHandshakeTimeout() time.Duration { return sb.HandshakeTimeout } @@ -83,6 +86,11 @@ func (sb *SocketBuilders) GetWriteBufferSize() int { } func (sb *SocketBuilders) Validate() { + if nil == sb.SocketHandler { + logging.Logger().Panic("Websocket Fasthttp: SocketHandler must be specified") + } + sb.SocketHandler.Validate() + if 0 >= sb.HandshakeTimeout { sb.HandshakeTimeout = cwf.DefaultHandshakeTimeout }