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 ( import (
"encoding/json" "encoding/json"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/samuel/go-zookeeper/zk"
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
@ -16,6 +17,7 @@ type Ls struct {
Path string `json:"path"` Path string `json:"path"`
State string `json:"state"` State string `json:"state"`
Error string `json:"error"` Error string `json:"error"`
ZkStat *zk.Stat `json:"zkstat"`
} }
// Get ... // Get ...
@ -23,6 +25,7 @@ type Get struct {
Path string `json:"path"` Path string `json:"path"`
State string `json:"state"` State string `json:"state"`
Error string `json:"error"` Error string `json:"error"`
ZkStat *zk.Stat `json:"zkstat"`
Data []byte `json:"data"` Data []byte `json:"data"`
} }

View File

@ -48,7 +48,7 @@ func (z ZooNode) GetChildrens(path string) Ls {
var l Ls var l Ls
l.State = "OK" l.State = "OK"
childrens, _, err := z.Conn.Children(lsPath) childrens, zkStat, err := z.Conn.Children(lsPath)
if err != nil { if err != nil {
l.State = "ERROR" l.State = "ERROR"
l.Error = err.Error() l.Error = err.Error()
@ -58,6 +58,7 @@ func (z ZooNode) GetChildrens(path string) Ls {
l.Error = "" l.Error = ""
l.Childrens = childrens l.Childrens = childrens
l.Path = lsPath l.Path = lsPath
l.ZkStat = zkStat
return l return l
} }
@ -79,7 +80,7 @@ func (z ZooNode) GetNode(path string) Get {
var g Get var g Get
g.State = "OK" g.State = "OK"
data, _, err := z.Conn.Get(getPath) data, zkStat, err := z.Conn.Get(getPath)
if err != nil { if err != nil {
g.State = "ERROR" g.State = "ERROR"
g.Error = err.Error() g.Error = err.Error()
@ -89,6 +90,7 @@ func (z ZooNode) GetNode(path string) Get {
g.Error = "" g.Error = ""
g.Data = data g.Data = data
g.Path = getPath g.Path = getPath
g.ZkStat = zkStat
return g return g
} }