tcptemplate/zk/zkcli.go

43 lines
752 B
Go
Raw Normal View History

package zk
2019-02-28 10:01:09 +00:00
import (
2019-02-28 10:01:09 +00:00
_ "bytes"
zk "github.com/samuel/go-zookeeper/zk"
2019-03-13 01:20:09 +00:00
"go-tcpFramework-rudy/config"
"log"
"os"
_ "strings"
2019-02-28 10:01:09 +00:00
"time"
)
var g_zkCnn *zk.Conn
type ServerStatus struct {
2019-02-28 10:01:09 +00:00
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)
2019-02-28 10:01:09 +00:00
g_zkCnn, evChan, e = zk.Connect(config.Configs().Zkserver, time.Second)
if nil != e {
log.Println("", e.Error())
return e
}
2019-02-28 10:01:09 +00:00
if evChan == nil {
log.Println("")
os.Exit(1)
}
2019-02-28 10:01:09 +00:00
if g_zkCnn == nil {
log.Println("[ERROR] could not connect zookeeper")
os.Exit(1)
}
2019-02-28 10:01:09 +00:00
return nil
}
2019-02-28 10:01:09 +00:00
func ZkInstance() *zk.Conn {
return g_zkCnn
2019-02-28 10:01:09 +00:00
}