zookeeper/zookeeper.go

34 lines
534 B
Go
Raw Permalink Normal View History

2021-08-09 03:12:08 +00:00
package zookeeper
import (
"fmt"
"time"
2022-10-30 01:52:41 +00:00
"git.selly.red/Selly-Modules/logger"
2021-08-09 03:12:08 +00:00
"github.com/samuel/go-zookeeper/zk"
)
var zkClient *zk.Conn
// Connect ...
func Connect(uri string) error {
c, _, err := zk.Connect([]string{uri}, time.Second*30)
if err != nil {
2022-10-30 01:52:41 +00:00
logger.Error("connect", logger.LogData{
Source: "zookeeper.Connect",
Message: err.Error(),
Data: logger.Map{
"uri": uri,
},
})
2021-08-09 03:12:08 +00:00
return err
}
2022-10-30 01:52:41 +00:00
fmt.Printf("⚡️[zookeeper]: connected to %s \n", uri)
2021-08-09 03:12:08 +00:00
// Set client
zkClient = c
return nil
}