2018-04-12 01:23:40 +00:00
|
|
|
package client
|
2018-04-11 09:27:16 +00:00
|
|
|
|
2018-04-13 07:11:43 +00:00
|
|
|
import "sync/atomic"
|
|
|
|
|
2018-04-12 01:23:40 +00:00
|
|
|
type Connector interface {
|
2018-04-11 09:27:16 +00:00
|
|
|
Connect() (readChan <-chan []byte, writeChan chan<- []byte, err error)
|
|
|
|
Disconnect() error
|
2018-04-12 01:23:40 +00:00
|
|
|
|
2018-04-12 05:55:01 +00:00
|
|
|
GetName() string
|
|
|
|
|
|
|
|
Clone() Connector
|
2018-04-12 01:23:40 +00:00
|
|
|
Validate() error
|
2018-04-11 09:27:16 +00:00
|
|
|
}
|
2018-04-12 05:55:01 +00:00
|
|
|
|
|
|
|
type Connectors struct {
|
|
|
|
Name string `json:"name"`
|
2018-04-13 07:11:43 +00:00
|
|
|
|
|
|
|
validated atomic.Value
|
2018-04-12 05:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Connectors) GetName() string {
|
|
|
|
return c.Name
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Connectors) Clone() *Connectors {
|
|
|
|
return &Connectors{
|
2018-04-13 07:11:43 +00:00
|
|
|
Name: c.Name,
|
|
|
|
validated: c.validated,
|
2018-04-12 05:55:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Connectors) Validate() error {
|
2018-04-13 07:11:43 +00:00
|
|
|
if nil != c.validated.Load() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
c.validated.Store(true)
|
|
|
|
|
2018-04-12 05:55:01 +00:00
|
|
|
if "" == c.Name {
|
|
|
|
c.Name = "Connector"
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|