Zk stat in JSON output in ls and get methods

This commit is contained in:
Denis Zheleztsov 2017-02-18 20:12:50 +03:00
parent 2f36285360
commit c0a473682e
2 changed files with 11 additions and 6 deletions

View File

@ -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 ...

View File

@ -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
}