123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package clinit
- /*
- import (
- "fmt"
- "os"
- "strings"
- "time"
- "go.etcd.io/etcd/client"
- )
- var etcdClient client.Client
- func InitEtcd(etcdaddrs []string) {
- endpoints := []string{}
- for _, addr := range etcdaddrs {
- if strings.HasPrefix(addr, "http://") {
- endpoints = append(endpoints, addr)
- } else {
- endpoints = append(endpoints, fmt.Sprintf("http://%s", addr))
- }
- }
- cli, err := client.New(client.Config{
- Endpoints: endpoints,
- Transport: client.DefaultTransport,
- HeaderTimeoutPerRequest: 5 * time.Second,
- })
- if err != nil {
- fmt.Printf("new etcd client failed. error:%s\n", err)
- os.Exit(1)
- }
- etcdClient = cli
- }
- func GetEtcdClient() client.Client {
- return etcdClient
- }*/
- import (
- clientv3 "go.etcd.io/etcd/client/v3"
- )
- var cli *clientv3.Client
- func GetEtcdClient() *clientv3.Client {
- return cli
- }
- func EctdHandler(etcdAddrs []string) {
- var err error
- cli, err = clientv3.New(clientv3.Config{
- Endpoints: etcdAddrs,
- })
- if err != nil {
- panic(err)
- }
- return
- }
|