Ejemplo n.º 1
0
func Import(r render.Render, req *http.Request, zc *zk.Conn) {
	data, _ := ioutil.ReadAll(req.Body)
	param := make(map[string]string)
	json.Unmarshal(data, &param)
	err := zc.Import(param)
	if err != nil {
		r.JSON(500, false)
	} else {
		r.JSON(200, true)
	}
}
Ejemplo n.º 2
0
func Delete(r render.Render, req *http.Request, zc *zk.Conn) {
	data, _ := ioutil.ReadAll(req.Body)
	param := make(map[string]interface{})
	json.Unmarshal(data, &param)
	path, _ := param["path"].(string)
	err := zc.Delete(path)
	if err != nil {
		r.JSON(500, false)
	} else {
		r.JSON(200, true)
	}
}
Ejemplo n.º 3
0
func Export(r render.Render, req *http.Request, zc *zk.Conn) {
	path := req.URL.Query().Get("path")
	if path == "" {
		path = "/"
	}
	pathValues, err := zc.Export(path)
	if err != nil {
		r.JSON(500, false)
	} else {
		r.JSON(200, pathValues)
	}
}
Ejemplo n.º 4
0
func FindByPath(r render.Render, req *http.Request, zc *zk.Conn) {
	path := req.URL.Query().Get("path")
	key := req.URL.Query().Get("key")
	t := req.URL.Query().Get("type")
	var pathValues interface{}
	var err error
	if t == "val" {
		pathValues, err = zc.FindNodeByVal(path, key)
	} else {
		pathValues, err = zc.FindNodeByPath(path, key)
	}
	if err != nil {
		r.JSON(500, false)
	} else {
		r.JSON(200, pathValues)
	}
}
Ejemplo n.º 5
0
func Create(r render.Render, req *http.Request, zc *zk.Conn) {
	data, _ := ioutil.ReadAll(req.Body)
	param := make(map[string]interface{})
	json.Unmarshal(data, &param)
	var parent, name, value string
	if val := param["parent"]; val != nil {
		parent, _ = val.(string)
	}
	if val := param["name"]; val != nil {
		name, _ = val.(string)
	}
	if val := param["value"]; val != nil {
		value, _ = val.(string)
	}
	path := path.Join(parent, name)
	err := zc.CreateData(path, value)
	if err != nil {
		r.JSON(500, false)
	} else {
		r.JSON(200, true)
	}
}
Ejemplo n.º 6
0
func State(r render.Render, req *http.Request, zc *zk.Conn) {
	path := req.URL.Query().Get("path")
	state, _ := zc.NodeState(path)
	r.JSON(200, state)
}
Ejemplo n.º 7
0
func NodeData(r render.Render, req *http.Request, zc *zk.Conn) {
	path := req.URL.Query().Get("path")
	data, _ := zc.NodeData(path)
	r.JSON(200, data)
}
Ejemplo n.º 8
0
func Childrens(r render.Render, req *http.Request, zc *zk.Conn) {
	path := req.URL.Query().Get("path")
	data, _ := zc.Childrens(path)
	r.JSON(200, data)
}