41 lines
730 B
Go
41 lines
730 B
Go
|
package zk
|
||
|
import (
|
||
|
zk "github.com/samuel/go-zookeeper/zk"
|
||
|
"time"
|
||
|
"log"
|
||
|
"os"
|
||
|
_ "strings"
|
||
|
_ "bytes"
|
||
|
"tcpserv/config"
|
||
|
)
|
||
|
|
||
|
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
|
||
|
}
|