This commit is contained in:
2024-10-24 01:16:25 +07:00
parent 40a6b71865
commit 6bef3f45cd
5 changed files with 84 additions and 80 deletions

View File

@ -38,31 +38,29 @@ type FlexSpot struct {
}
type FlexClient struct {
Address string
Port string
Timeout time.Duration
LogWriter *bufio.Writer
Reader *bufio.Reader
Writer *bufio.Writer
Conn *net.TCPConn
SpotChan chan TelnetSpot
MsgChan chan string
FlexSpotChan chan FlexSpot
Repo FlexDXClusterRepository
TCPServer *TCPServer
IsConnected bool
Address string
Port string
Timeout time.Duration
LogWriter *bufio.Writer
Reader *bufio.Reader
Writer *bufio.Writer
Conn *net.TCPConn
SpotChanToFlex chan TelnetSpot
MsgChan chan string
Repo FlexDXClusterRepository
TCPServer *TCPServer
IsConnected bool
}
func NewFlexClient(repo FlexDXClusterRepository, TCPServer *TCPServer) *FlexClient {
func NewFlexClient(repo FlexDXClusterRepository, TCPServer *TCPServer, SpotChanToFlex chan TelnetSpot) *FlexClient {
return &FlexClient{
Address: Cfg.Flex.IP,
Port: "4992",
SpotChan: make(chan TelnetSpot, 100),
FlexSpotChan: make(chan FlexSpot, 100),
MsgChan: TCPServer.MsgChan,
Repo: repo,
TCPServer: TCPServer,
IsConnected: false,
Address: Cfg.Flex.IP,
Port: "4992",
SpotChanToFlex: SpotChanToFlex,
MsgChan: TCPServer.MsgChan,
Repo: repo,
TCPServer: TCPServer,
IsConnected: false,
}
}
@ -91,7 +89,7 @@ func (fc *FlexClient) StartFlexClient() {
fc.IsConnected = true
go func() {
for message := range fc.SpotChan {
for message := range fc.SpotChanToFlex {
fc.SendSpottoFlex(message)
}
}()
@ -188,11 +186,6 @@ func (fc *FlexClient) SendSpottoFlex(spot TelnetSpot) {
Log.Debugf("could not find the DX in the database: ", err)
}
// send FlexSpot to HTTP Server
if Cfg.General.HTTPServer {
fc.FlexSpotChan <- flexSpot
}
var stringSpot string
if srcFlexSpot.DX == "" {
fc.Repo.CreateSpot(flexSpot)