init
This commit is contained in:
parent
43a9b30fd2
commit
88b0cb22ca
11
collector.go
11
collector.go
@ -112,9 +112,16 @@ func (coll *Collector) parse(res *Response) {
|
||||
// Set result
|
||||
elem := reflect.ValueOf(node).Elem()
|
||||
field := elem.FieldByName(strings.Title(coll.collectType))
|
||||
field.Set(reflect.ValueOf(result))
|
||||
|
||||
nodeserver.SendAll(node)
|
||||
log.Println(field)
|
||||
log.Println(result)
|
||||
|
||||
if !reflect.DeepEqual(field,result){
|
||||
nodeserver.SendAll(node)
|
||||
log.Println("get a node update")
|
||||
}
|
||||
|
||||
field.Set(reflect.ValueOf(result))
|
||||
}
|
||||
|
||||
func (coll *Collector) receiver() {
|
||||
|
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
"golang.org/x/net/websocket"
|
||||
)
|
||||
@ -58,18 +57,16 @@ func (c *NodeClient) Done() {
|
||||
|
||||
// Listen Write and Read request via chanel
|
||||
func (c *NodeClient) Listen() {
|
||||
go c.listenWrite()
|
||||
c.listenWrite()
|
||||
}
|
||||
|
||||
// Listen write request via chanel
|
||||
func (c *NodeClient) listenWrite() {
|
||||
log.Println("Listening write to NodeClient")
|
||||
for {
|
||||
select {
|
||||
|
||||
// send message to the client
|
||||
case node := <-c.ch:
|
||||
log.Println("Send:", node)
|
||||
websocket.JSON.Send(c.ws, node)
|
||||
|
||||
// receive done request
|
||||
|
@ -102,7 +102,6 @@ func (s *NodeServer) Listen() {
|
||||
|
||||
// broadcast message for all clients
|
||||
case node := <-s.sendAllCh:
|
||||
log.Println("Send all:", node)
|
||||
s.sendAll(node)
|
||||
|
||||
case err := <-s.errCh:
|
||||
|
Loading…
Reference in New Issue
Block a user