func Import(r render.Render, req *http.Request, zc *zk.Conn) { data, _ := ioutil.ReadAll(req.Body) param := make(map[string]string) json.Unmarshal(data, ¶m) err := zc.Import(param) if err != nil { r.JSON(500, false) } else { r.JSON(200, true) } }
func Delete(r render.Render, req *http.Request, zc *zk.Conn) { data, _ := ioutil.ReadAll(req.Body) param := make(map[string]interface{}) json.Unmarshal(data, ¶m) path, _ := param["path"].(string) err := zc.Delete(path) if err != nil { r.JSON(500, false) } else { r.JSON(200, true) } }
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) } }
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) } }
func Create(r render.Render, req *http.Request, zc *zk.Conn) { data, _ := ioutil.ReadAll(req.Body) param := make(map[string]interface{}) json.Unmarshal(data, ¶m) 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) } }
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) }
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) }
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) }