From 88b0cb22ca6802debac6c88737b758e8b71a1103 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Fri, 19 Feb 2016 13:28:06 +0100 Subject: [PATCH] init --- collector.go | 11 +++++++++-- nodeclient.go | 5 +---- nodeserver.go | 1 - 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/collector.go b/collector.go index b4922b3..9329a3a 100644 --- a/collector.go +++ b/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() { diff --git a/nodeclient.go b/nodeclient.go index addbf8e..92dbd80 100644 --- a/nodeclient.go +++ b/nodeclient.go @@ -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 diff --git a/nodeserver.go b/nodeserver.go index ed69862..9906ed0 100644 --- a/nodeserver.go +++ b/nodeserver.go @@ -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: