clientv3\balancer\resolver\endpoint\endpoint.go:114:87: undefined: resolver.BuildOption

新版本etcd已经改为:

main.go

import clientv3 "go.etcd.io/etcd/client/v3"

go.mod:

go 1.23.3
require go.etcd.io/etcd/client/v3 v3.5.17

参考最新的官方文档:

https://github.com/etcd-io/etcd/blob/main/client/v3/README.md

etcd/clientv3 is the official Go etcd client for v3.

Install

go get go.etcd.io/etcd/client/v3

Get started

Create client using clientv3.New:

import clientv3 "go.etcd.io/etcd/client/v3"

func main() {
	cli, err := clientv3.New(clientv3.Config{
		Endpoints:   []string{"localhost:2379", "localhost:22379", "localhost:32379"},
		DialTimeout: 5 * time.Second,
	})
	if err != nil {
		// handle error!
	}
	defer cli.Close()
}

etcd v3 uses gRPC for remote procedure calls. And clientv3 uses grpc-go to connect to etcd. Make sure to close the client after using it. If the client is not closed, the connection will have leaky goroutines. To specify client request timeout, pass context.WithTimeout to APIs:

ctx, cancel := context.WithTimeout(context.Background(), timeout)
resp, err := cli.Put(ctx, "sample_key", "sample_value")
cancel()
if err != nil {
    // handle error!
}
// use the response

For full compatibility, it is recommended to install released versions of clients using go modules.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值