tcptemplate/zk/zkcli.go

43 lines
752 B
Go

package zk
import (
_ "bytes"
zk "github.com/samuel/go-zookeeper/zk"
"go-tcpFramework-rudy/config"
"log"
"os"
_ "strings"
"time"
)
var g_zkCnn *zk.Conn
type ServerStatus struct {
CnnCount int32 `json:"cnn_count"` //当前在线连接数目
ServerID string `json:"server_id"` //serverID
}
func ConnectZooKeeper() error {
var e error
var evChan <-chan zk.Event
log.Println(config.Configs().Zkserver)
g_zkCnn, evChan, e = zk.Connect(config.Configs().Zkserver, time.Second)
if nil != e {
log.Println("", e.Error())
return e
}
if evChan == nil {
log.Println("")
os.Exit(1)
}
if g_zkCnn == nil {
log.Println("[ERROR] could not connect zookeeper")
os.Exit(1)
}
return nil
}
func ZkInstance() *zk.Conn {
return g_zkCnn
}