Example #1
0
func Get(zh *u.ZH, path string) (content string, stat zk.Stat, err error) {
	var read []byte
	read, stat, err = zh.Get(path)
	if err == nil {
		content = string(read)
	}
	return
}
Example #2
0
func DelChildNode(zh *u.ZH, path string) (err error) {
	var childNodes []string
	var stat zk.Stat
	childNodes, err = zh.Children(path)
	if err != nil {
		fmt.Println("get node %s clindren error: %s", path, err.Error())
		return
	}
	fmt.Println("begin to del node:", childNodes)
	for _, node := range childNodes {
		nodeToDel := fmt.Sprintf("%s/%s", path, node)
		_, stat, err = zh.Get(nodeToDel)
		if err != nil {
			fmt.Println("get zk node fail:", nodeToDel, err.Error())
			return
		} else {
			fmt.Println("begin to del node:", nodeToDel)
		}
		err = zh.Delete(nodeToDel, int32(stat.Version()))
		if err != nil {
			fmt.Printf("del node %s error: %s", nodeToDel, err.Error())
			continue
		}
	}
	return
}
Example #3
0
func WatchChildren(zh *u.ZH, path string) (children []string, event <-chan zk.Event, err error) {
	children, event, err = zh.ChildrenW(path)
	return
}
Example #4
0
func WatchExist(zh *u.ZH, path string) (ok bool, event <-chan zk.Event) {
	ok, event = zh.ExistsW(path)
	return
}
Example #5
0
func Create(zh *u.ZH, path string, data []byte, flags int32) (string, error) {
	return zh.Create(path, data, flags)
}
Example #6
0
func GetLock(zh *u.ZH, path string) *zk.Lock {
	return zh.NewLock(path)
}
Example #7
0
func Set(zh *u.ZH, path string, data []byte, version int32) (stat zk.Stat, err error) {
	stat, err = zh.Set(path, data, version)
	return
}
Example #8
0
func Children(zh *u.ZH, path string) (paths []string, err error) {
	paths, err = zh.Children(path)
	return
}