44 lines
656 B
Go
44 lines
656 B
Go
package client
|
|
|
|
import "sync/atomic"
|
|
|
|
type Connector interface {
|
|
Connect() (readChan <-chan []byte, writeChan chan<- []byte, err error)
|
|
Disconnect() error
|
|
|
|
GetName() string
|
|
|
|
Clone() Connector
|
|
Validate() error
|
|
}
|
|
|
|
type Connectors struct {
|
|
Name string `json:"name,omitempty"`
|
|
|
|
validated atomic.Value
|
|
}
|
|
|
|
func (c *Connectors) GetName() string {
|
|
return c.Name
|
|
}
|
|
|
|
func (c *Connectors) Clone() *Connectors {
|
|
return &Connectors{
|
|
Name: c.Name,
|
|
validated: c.validated,
|
|
}
|
|
}
|
|
|
|
func (c *Connectors) Validate() error {
|
|
if nil != c.validated.Load() {
|
|
return nil
|
|
}
|
|
c.validated.Store(true)
|
|
|
|
if "" == c.Name {
|
|
c.Name = "Connector"
|
|
}
|
|
|
|
return nil
|
|
}
|