30 lines
498 B
Go
30 lines
498 B
Go
package etcd
|
|
|
|
import (
|
|
commonConfig "common/config"
|
|
"fmt"
|
|
clientv3 "go.etcd.io/etcd/client/v3"
|
|
)
|
|
|
|
var etcdClient *clientv3.Client
|
|
|
|
func Init(cfg *commonConfig.EtcdConfig) error {
|
|
client, err := clientv3.New(clientv3.Config{
|
|
Endpoints: []string{fmt.Sprintf("%v:%v", cfg.Host, cfg.Port)},
|
|
DialTimeout: 0,
|
|
})
|
|
etcdClient = client
|
|
return err
|
|
}
|
|
|
|
func Close() error {
|
|
if etcdClient != nil {
|
|
return etcdClient.Close()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func Client() *clientv3.Client {
|
|
return etcdClient
|
|
}
|