ing
This commit is contained in:
parent
20a63b3de6
commit
cbe8e30db4
|
@ -9,6 +9,9 @@ import (
|
||||||
type OnDisconnectedFunc func(connector Connector)
|
type OnDisconnectedFunc func(connector Connector)
|
||||||
|
|
||||||
type Connector interface {
|
type Connector interface {
|
||||||
|
socket.ClientConnHandler
|
||||||
|
socket.ReadWriteHandler
|
||||||
|
|
||||||
Connect() (readChan <-chan socket.SocketMessage, writeChan chan<- socket.SocketMessage, err error)
|
Connect() (readChan <-chan socket.SocketMessage, writeChan chan<- socket.SocketMessage, err error)
|
||||||
Disconnect() error
|
Disconnect() error
|
||||||
|
|
||||||
|
@ -21,6 +24,9 @@ type Connector interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Connectors struct {
|
type Connectors struct {
|
||||||
|
socket.ClientConnHandlers
|
||||||
|
socket.ReadWriteHandlers
|
||||||
|
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
OnDisconnected OnDisconnectedFunc `json:"-"`
|
OnDisconnected OnDisconnectedFunc `json:"-"`
|
||||||
|
|
||||||
|
@ -41,8 +47,10 @@ func (c *Connectors) SetOnDisconnected(fnc OnDisconnectedFunc) {
|
||||||
|
|
||||||
func (c *Connectors) Clone() *Connectors {
|
func (c *Connectors) Clone() *Connectors {
|
||||||
return &Connectors{
|
return &Connectors{
|
||||||
Name: c.Name,
|
Name: c.Name,
|
||||||
validated: c.validated,
|
ClientConnHandlers: *c.ClientConnHandlers.Clone(),
|
||||||
|
ReadWriteHandlers: *c.ReadWriteHandlers.Clone(),
|
||||||
|
validated: c.validated,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +60,13 @@ func (c *Connectors) Validate() error {
|
||||||
}
|
}
|
||||||
c.validated.Store(true)
|
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 {
|
if "" == c.Name {
|
||||||
c.Name = "Connector"
|
c.Name = "Connector"
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,6 @@ import (
|
||||||
|
|
||||||
type Connectors struct {
|
type Connectors struct {
|
||||||
client.Connectors
|
client.Connectors
|
||||||
socket.ClientConnHandlers
|
|
||||||
socket.ReadWriteHandlers
|
|
||||||
|
|
||||||
Network string `json:"network,omitempty"`
|
Network string `json:"network,omitempty"`
|
||||||
Address string `json:"address,omitempty"`
|
Address string `json:"address,omitempty"`
|
||||||
|
@ -191,13 +189,11 @@ func (c *Connectors) dial() (net.Conn, error) {
|
||||||
|
|
||||||
func (c *Connectors) Clone() client.Connector {
|
func (c *Connectors) Clone() client.Connector {
|
||||||
return &Connectors{
|
return &Connectors{
|
||||||
Connectors: *c.Connectors.Clone(),
|
Connectors: *c.Connectors.Clone(),
|
||||||
ClientConnHandlers: *c.ClientConnHandlers.Clone(),
|
Network: c.Network,
|
||||||
ReadWriteHandlers: *c.ReadWriteHandlers.Clone(),
|
Address: c.Address,
|
||||||
Network: c.Network,
|
LocalAddress: c.LocalAddress,
|
||||||
Address: c.Address,
|
validated: c.validated,
|
||||||
LocalAddress: c.LocalAddress,
|
|
||||||
validated: c.validated,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,12 +206,6 @@ func (c *Connectors) Validate() error {
|
||||||
if err := c.Connectors.Validate(); nil != err {
|
if err := c.Connectors.Validate(); nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.ClientConnHandlers.Validate(); nil != err {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := c.ReadWriteHandlers.Validate(); nil != err {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if "" == c.Network {
|
if "" == c.Network {
|
||||||
return fmt.Errorf("%s Network is not valid", c.logHeader())
|
return fmt.Errorf("%s Network is not valid", c.logHeader())
|
||||||
|
|
|
@ -27,8 +27,6 @@ var errMalformedURL = errors.New("malformed ws or wss URL")
|
||||||
|
|
||||||
type Connectors struct {
|
type Connectors struct {
|
||||||
client.Connectors
|
client.Connectors
|
||||||
socket.ClientConnHandlers
|
|
||||||
socket.ReadWriteHandlers
|
|
||||||
|
|
||||||
URL string `json:"url,omitempty"`
|
URL string `json:"url,omitempty"`
|
||||||
|
|
||||||
|
@ -482,18 +480,16 @@ func cloneTLSConfig(cfg *tls.Config) *tls.Config {
|
||||||
|
|
||||||
func (c *Connectors) Clone() client.Connector {
|
func (c *Connectors) Clone() client.Connector {
|
||||||
return &Connectors{
|
return &Connectors{
|
||||||
Connectors: *c.Connectors.Clone(),
|
Connectors: *c.Connectors.Clone(),
|
||||||
ClientConnHandlers: *c.ClientConnHandlers.Clone(),
|
URL: c.URL,
|
||||||
ReadWriteHandlers: *c.ReadWriteHandlers.Clone(),
|
RequestHeader: c.RequestHeader,
|
||||||
URL: c.URL,
|
Subprotocols: c.Subprotocols,
|
||||||
RequestHeader: c.RequestHeader,
|
CookieJar: c.CookieJar,
|
||||||
Subprotocols: c.Subprotocols,
|
ResponseHandler: c.ResponseHandler,
|
||||||
CookieJar: c.CookieJar,
|
NetDial: c.NetDial,
|
||||||
ResponseHandler: c.ResponseHandler,
|
Proxy: c.Proxy,
|
||||||
NetDial: c.NetDial,
|
serverURL: c.serverURL,
|
||||||
Proxy: c.Proxy,
|
validated: c.validated,
|
||||||
serverURL: c.serverURL,
|
|
||||||
validated: c.validated,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,12 +502,6 @@ func (c *Connectors) Validate() error {
|
||||||
if err := c.Connectors.Validate(); nil != err {
|
if err := c.Connectors.Validate(); nil != err {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := c.ClientConnHandlers.Validate(); nil != err {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := c.ReadWriteHandlers.Validate(); nil != err {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if "" == c.URL {
|
if "" == c.URL {
|
||||||
return fmt.Errorf("URL is not valid")
|
return fmt.Errorf("URL is not valid")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user