加入网络层

This commit is contained in:
2025-06-26 23:57:54 +08:00
parent 53106465ed
commit 0f29dccec4
57 changed files with 1859 additions and 1274 deletions

View File

@@ -1,29 +1,28 @@
package etcd
import (
commonConfig "common/config"
"fmt"
clientv3 "go.etcd.io/etcd/client/v3"
"go.etcd.io/etcd/client/v3"
"time"
)
var etcdClient *clientv3.Client
var cli *clientv3.Client
func Init(cfg *commonConfig.EtcdConfig) error {
func Init(endpoints []string) error {
client, err := clientv3.New(clientv3.Config{
Endpoints: []string{fmt.Sprintf("%v:%v", cfg.Host, cfg.Port)},
DialTimeout: 0,
Endpoints: endpoints,
DialTimeout: 5 * time.Second,
})
etcdClient = client
cli = client
return err
}
func Client() *clientv3.Client {
return cli
}
func Close() error {
if etcdClient != nil {
return etcdClient.Close()
if cli != nil {
return cli.Close()
}
return nil
}
func Client() *clientv3.Client {
return etcdClient
}