This commit is contained in:
crusader 2017-12-08 16:41:43 +09:00
parent af27365039
commit a5e92f2b11
3 changed files with 14 additions and 10 deletions

View File

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

View File

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

View File

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