func InitZK() (*zk.Conn, error) { config := GetConfig() if config == nil { log.Fatal("get config error") } conn, err := myzk.Connect(config.Zk.ZookeeperAddr, config.Zk.ZookeeperTimeout) if err != nil { log.Error("myzk.Connect() error(%v)", err) return nil, err } fpath := path.Join(ZOOKEEPER_GATE_PATH, config.Zk.ZookeeperNode) err := myzk.DeleteNode(conn, fpath) if err != nil { log.Error("myzk delete node error:%v", err) } data := []byte{} log.Debug("myzk node:\"%s\" registe data: \"%s\"", fpath, string(data)) if err = myzk.RegisterTemp(conn, fpath, data); err != nil { log.Error("myzk.RegisterTemp() error(%v)", err) return conn, err } go WatchConnChange(conn) return conn, nil }
func InitZK() (*zk.Conn, error) { config := GetConfig() if config == nil { log.Fatal("get config error") } conn, err := myzk.Connect(config.Zk.ZookeeperAddr, config.Zk.ZookeeperTimeout) if err != nil { log.Error("myzk.Connect() error(%v)", err) return nil, err } fpath := path.Join(ZOOKEEPER_CONN_PATH, config.Zk.ZookeeperNode) nodeInfo := ConnectorConf{ Hostname: config.Zk.ZookeeperNode, ServeAddr: config.ServeAddr, RpcAddr: config.RpcAddr, } data, err := json.Marshal(nodeInfo) if err != nil { log.Error("json.Marshal() error(%v)", err) return conn, err } log.Debug("myzk node:\"%s\" registe data: \"%s\"", fpath, string(data)) err = myzk.DeleteNode(conn, fpath) if err != nil { log.Error("myzk delete node error:%v", err) } if err = myzk.RegisterTemp(conn, fpath, data); err != nil { log.Error("myzk.RegisterTemp() error(%v)", err) return conn, err } return conn, nil }