From c0a473682e587964aa77c721930729c27870cbd5 Mon Sep 17 00:00:00 2001 From: Denis Zheleztsov Date: Sat, 18 Feb 2017 20:12:50 +0300 Subject: [PATCH] Zk stat in JSON output in ls and get methods --- rest/api.go | 11 +++++++---- rest/zoo.go | 6 ++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/rest/api.go b/rest/api.go index b552032..2f803af 100644 --- a/rest/api.go +++ b/rest/api.go @@ -3,6 +3,7 @@ package rest import ( "encoding/json" "github.com/gorilla/mux" + "github.com/samuel/go-zookeeper/zk" "io/ioutil" "log" "net/http" @@ -16,14 +17,16 @@ type Ls struct { Path string `json:"path"` State string `json:"state"` Error string `json:"error"` + ZkStat *zk.Stat `json:"zkstat"` } // Get ... type Get struct { - Path string `json:"path"` - State string `json:"state"` - Error string `json:"error"` - Data []byte `json:"data"` + Path string `json:"path"` + State string `json:"state"` + Error string `json:"error"` + ZkStat *zk.Stat `json:"zkstat"` + Data []byte `json:"data"` } // LS ... diff --git a/rest/zoo.go b/rest/zoo.go index cf8429d..473dd30 100644 --- a/rest/zoo.go +++ b/rest/zoo.go @@ -48,7 +48,7 @@ func (z ZooNode) GetChildrens(path string) Ls { var l Ls l.State = "OK" - childrens, _, err := z.Conn.Children(lsPath) + childrens, zkStat, err := z.Conn.Children(lsPath) if err != nil { l.State = "ERROR" l.Error = err.Error() @@ -58,6 +58,7 @@ func (z ZooNode) GetChildrens(path string) Ls { l.Error = "" l.Childrens = childrens l.Path = lsPath + l.ZkStat = zkStat return l } @@ -79,7 +80,7 @@ func (z ZooNode) GetNode(path string) Get { var g Get g.State = "OK" - data, _, err := z.Conn.Get(getPath) + data, zkStat, err := z.Conn.Get(getPath) if err != nil { g.State = "ERROR" g.Error = err.Error() @@ -89,6 +90,7 @@ func (z ZooNode) GetNode(path string) Get { g.Error = "" g.Data = data g.Path = getPath + g.ZkStat = zkStat return g }