2021-08-09 03:12:08 +00:00
|
|
|
package zookeeper
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/samuel/go-zookeeper/zk"
|
|
|
|
)
|
|
|
|
|
|
|
|
var zkClient *zk.Conn
|
|
|
|
|
|
|
|
// Connect ...
|
|
|
|
func Connect(uri string) error {
|
2022-11-16 02:50:11 +00:00
|
|
|
c, _, err := zk.Connect([]string{uri}, time.Second*30, zk.WithLogInfo(false))
|
2021-08-09 03:12:08 +00:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println("Error when connect to Zookeeper", uri, err)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-11-16 02:53:19 +00:00
|
|
|
fmt.Printf("⚡️[zookeeper]: connected to %s \n", uri)
|
2021-08-09 03:12:08 +00:00
|
|
|
|
|
|
|
// Set client
|
|
|
|
zkClient = c
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|