package parser import ( "fmt" "os" "strings" client "go.etcd.io/etcd/client/v3" "property-applete-gateway/config" ) var etcdClient *client.Client func EtcdHandler(conf *config.Configure) { InitEtcd(conf.EtcdAddrs) } 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, }) if err != nil { fmt.Printf("new etcd client failed. error:%s\n", err) os.Exit(1) } etcdClient = cli } func GetEtcdClient() *client.Client { return etcdClient }