之前dubbo使用了zookeeper做服务注册,这块打算获取所有的接口路径,于是写了一个golang程序来做这件事情。
代码如下:
package main
import (
"fmt"
"time"
"github.com/samuel/go-zookeeper/zk"
)
func printPath(path string, c *zk.Conn) {
children, _ , err := c.Children(path)
if err == nil && len(children) != 0 {
for _, chlid := range children {
printPath(path+"/"+chlid, c)
}
} else {
fmt.Println(path)
}
}
func main() {
c, _, err := zk.Connect([]string{"zk01.mydomain.com:2181"}, time.Second)
if err != nil {
panic(err)
}
path := "mypath"
secret := "mypasswd"
c.AddAuth("digest", []byte(path+":"+secret))
printPath("/"+path, c)
}
有疑问加站长微信联系(非本文作者)