This commit is contained in:
2025-06-25 00:01:48 +08:00
parent 3d53c9ec59
commit 53106465ed
30 changed files with 2108 additions and 6 deletions

View File

@@ -0,0 +1,29 @@
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
}