From cbe8e30db48a21b33650c5ed7e7d8bbf4784c9d4 Mon Sep 17 00:00:00 2001 From: crusader Date: Mon, 2 Jul 2018 17:03:45 +0900 Subject: [PATCH] ing --- socket/client/connector.go | 19 +++++++++++++++++-- socket/net/client/connector.go | 20 +++++--------------- socket/web/client/connector.go | 30 ++++++++++-------------------- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/socket/client/connector.go b/socket/client/connector.go index 4592c0d..f30fb52 100644 --- a/socket/client/connector.go +++ b/socket/client/connector.go @@ -9,6 +9,9 @@ import ( type OnDisconnectedFunc func(connector Connector) type Connector interface { + socket.ClientConnHandler + socket.ReadWriteHandler + Connect() (readChan <-chan socket.SocketMessage, writeChan chan<- socket.SocketMessage, err error) Disconnect() error @@ -21,6 +24,9 @@ type Connector interface { } type Connectors struct { + socket.ClientConnHandlers + socket.ReadWriteHandlers + Name string `json:"name,omitempty"` OnDisconnected OnDisconnectedFunc `json:"-"` @@ -41,8 +47,10 @@ func (c *Connectors) SetOnDisconnected(fnc OnDisconnectedFunc) { func (c *Connectors) Clone() *Connectors { return &Connectors{ - Name: c.Name, - validated: c.validated, + Name: c.Name, + ClientConnHandlers: *c.ClientConnHandlers.Clone(), + ReadWriteHandlers: *c.ReadWriteHandlers.Clone(), + validated: c.validated, } } @@ -52,6 +60,13 @@ func (c *Connectors) Validate() error { } c.validated.Store(true) + if err := c.ClientConnHandlers.Validate(); nil != err { + return err + } + if err := c.ReadWriteHandlers.Validate(); nil != err { + return err + } + if "" == c.Name { c.Name = "Connector" } diff --git a/socket/net/client/connector.go b/socket/net/client/connector.go index 6fb7ba2..8848f31 100644 --- a/socket/net/client/connector.go +++ b/socket/net/client/connector.go @@ -15,8 +15,6 @@ import ( type Connectors struct { client.Connectors - socket.ClientConnHandlers - socket.ReadWriteHandlers Network string `json:"network,omitempty"` Address string `json:"address,omitempty"` @@ -191,13 +189,11 @@ func (c *Connectors) dial() (net.Conn, error) { func (c *Connectors) Clone() client.Connector { return &Connectors{ - Connectors: *c.Connectors.Clone(), - ClientConnHandlers: *c.ClientConnHandlers.Clone(), - ReadWriteHandlers: *c.ReadWriteHandlers.Clone(), - Network: c.Network, - Address: c.Address, - LocalAddress: c.LocalAddress, - validated: c.validated, + Connectors: *c.Connectors.Clone(), + Network: c.Network, + Address: c.Address, + LocalAddress: c.LocalAddress, + validated: c.validated, } } @@ -210,12 +206,6 @@ func (c *Connectors) Validate() error { if err := c.Connectors.Validate(); nil != err { return err } - if err := c.ClientConnHandlers.Validate(); nil != err { - return err - } - if err := c.ReadWriteHandlers.Validate(); nil != err { - return err - } if "" == c.Network { return fmt.Errorf("%s Network is not valid", c.logHeader()) diff --git a/socket/web/client/connector.go b/socket/web/client/connector.go index ed975d8..102651a 100644 --- a/socket/web/client/connector.go +++ b/socket/web/client/connector.go @@ -27,8 +27,6 @@ var errMalformedURL = errors.New("malformed ws or wss URL") type Connectors struct { client.Connectors - socket.ClientConnHandlers - socket.ReadWriteHandlers URL string `json:"url,omitempty"` @@ -482,18 +480,16 @@ func cloneTLSConfig(cfg *tls.Config) *tls.Config { func (c *Connectors) Clone() client.Connector { return &Connectors{ - Connectors: *c.Connectors.Clone(), - ClientConnHandlers: *c.ClientConnHandlers.Clone(), - ReadWriteHandlers: *c.ReadWriteHandlers.Clone(), - URL: c.URL, - RequestHeader: c.RequestHeader, - Subprotocols: c.Subprotocols, - CookieJar: c.CookieJar, - ResponseHandler: c.ResponseHandler, - NetDial: c.NetDial, - Proxy: c.Proxy, - serverURL: c.serverURL, - validated: c.validated, + Connectors: *c.Connectors.Clone(), + URL: c.URL, + RequestHeader: c.RequestHeader, + Subprotocols: c.Subprotocols, + CookieJar: c.CookieJar, + ResponseHandler: c.ResponseHandler, + NetDial: c.NetDial, + Proxy: c.Proxy, + serverURL: c.serverURL, + validated: c.validated, } } @@ -506,12 +502,6 @@ func (c *Connectors) Validate() error { if err := c.Connectors.Validate(); nil != err { return err } - if err := c.ClientConnHandlers.Validate(); nil != err { - return err - } - if err := c.ReadWriteHandlers.Validate(); nil != err { - return err - } if "" == c.URL { return fmt.Errorf("URL is not valid")