ing
This commit is contained in:
parent
68341e3eb5
commit
d2e6df0fbf
|
@ -1,19 +1,26 @@
|
||||||
package client
|
package client
|
||||||
|
|
||||||
import "sync/atomic"
|
import (
|
||||||
|
"sync/atomic"
|
||||||
|
)
|
||||||
|
|
||||||
|
type OnDisconnectedFunc func(connector Connector)
|
||||||
|
|
||||||
type Connector interface {
|
type Connector interface {
|
||||||
Connect() (readChan <-chan []byte, writeChan chan<- []byte, err error)
|
Connect() (readChan <-chan []byte, writeChan chan<- []byte, err error)
|
||||||
Disconnect() error
|
Disconnect() error
|
||||||
|
|
||||||
GetName() string
|
GetName() string
|
||||||
|
GetOnDisconnected() OnDisconnectedFunc
|
||||||
|
SetOnDisconnected(fnc OnDisconnectedFunc)
|
||||||
|
|
||||||
Clone() Connector
|
Clone() Connector
|
||||||
Validate() error
|
Validate() error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Connectors struct {
|
type Connectors struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
|
OnDisconnected OnDisconnectedFunc `json:"-"`
|
||||||
|
|
||||||
validated atomic.Value
|
validated atomic.Value
|
||||||
}
|
}
|
||||||
|
@ -22,6 +29,14 @@ func (c *Connectors) GetName() string {
|
||||||
return c.Name
|
return c.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Connectors) GetOnDisconnected() OnDisconnectedFunc {
|
||||||
|
return c.OnDisconnected
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Connectors) SetOnDisconnected(fnc OnDisconnectedFunc) {
|
||||||
|
c.OnDisconnected = fnc
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Connectors) Clone() *Connectors {
|
func (c *Connectors) Clone() *Connectors {
|
||||||
return &Connectors{
|
return &Connectors{
|
||||||
Name: c.Name,
|
Name: c.Name,
|
||||||
|
|
|
@ -22,8 +22,6 @@ type Connectors struct {
|
||||||
Address string `json:"address,omitempty"`
|
Address string `json:"address,omitempty"`
|
||||||
LocalAddress net.Addr `json:"-"`
|
LocalAddress net.Addr `json:"-"`
|
||||||
|
|
||||||
OnDisconnected func(connector client.Connector) `json:"-"`
|
|
||||||
|
|
||||||
stopChan chan struct{}
|
stopChan chan struct{}
|
||||||
stopWg sync.WaitGroup
|
stopWg sync.WaitGroup
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,6 @@ type Connectors struct {
|
||||||
// If Proxy is nil or returns a nil *URL, no proxy is used.
|
// If Proxy is nil or returns a nil *URL, no proxy is used.
|
||||||
Proxy func(*http.Request) (*url.URL, error) `json:"-"`
|
Proxy func(*http.Request) (*url.URL, error) `json:"-"`
|
||||||
|
|
||||||
OnDisconnected func(connector client.Connector) `json:"-"`
|
|
||||||
|
|
||||||
serverURL *url.URL
|
serverURL *url.URL
|
||||||
|
|
||||||
stopChan chan struct{}
|
stopChan chan struct{}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user