当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
2 Star 0 Fork 1

JUMEI_ARCH/go-plugins
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
util.go 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
Asim 提交于 2016-05-21 18:54 . Cleanup the zookeeper registry some
package zookeeper
import (
"encoding/json"
"path"
"strings"
"github.com/micro/go-micro/registry"
"github.com/samuel/go-zookeeper/zk"
)
func encode(s *registry.Service) ([]byte, error) {
return json.Marshal(s)
}
func decode(ds []byte) (*registry.Service, error) {
var s *registry.Service
err := json.Unmarshal(ds, &s)
return s, err
}
func nodePath(s, id string) string {
service := strings.Replace(s, "/", "-", -1)
node := strings.Replace(id, "/", "-", -1)
return path.Join(prefix, service, node)
}
func servicePath(s string) string {
return path.Join(prefix, strings.Replace(s, "/", "-", -1))
}
func createPath(path string, data []byte, client *zk.Conn) error {
exists, _, err := client.Exists(path)
if err != nil {
return err
}
if exists {
return nil
}
name := "/"
p := strings.Split(path, "/")
for _, v := range p[1 : len(p)-1] {
name += v
e, _, _ := client.Exists(name)
if !e {
_, err = client.Create(name, []byte{}, int32(0), zk.WorldACL(zk.PermAll))
if err != nil {
return err
}
}
name += "/"
}
_, err = client.Create(path, data, int32(0), zk.WorldACL(zk.PermAll))
return err
}
func contains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/JMArch/go-plugins.git
git@gitee.com:JMArch/go-plugins.git
JMArch
go-plugins
go-plugins
v0.6.0

搜索帮助

0d507c66 1850385 C8b1a773 1850385