etcd undefined: resolver.BuildOption

使用ETCD clientv3包,遇到以下错误.
使用了go mod 

首先初始化 go mod init

接着go build 出现下面问题

github.com/coreos/etcd/clientv3/balancer/resolver/endpoint
..\..\..\..\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\resolver\endpoint\endpoint.go:114:78: undefined: resolver.BuildOption
..\..\..\..\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\resolver\endpoint\endpoint.go:182:31: undefined: resolver.ResolveNowOption
# github.com/coreos/etcd/clientv3/balancer/picker
..\..\..\..\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\picker\err.go:37:44: undefined: balancer.PickOptions
..\..\..\..\pkg\mod\github.com\coreos\[email protected]+incompatible\clientv3\balancer\picker\roundrobin_balanced.go:55:54: undefined: balancer.PickOptions

解决办法

找到go.mod文件

module studygo/day01/67etcd_demo

go 1.13

require (
	github.com/coreos/etcd v3.3.18+incompatible // indirect
	github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
	github.com/gogo/protobuf v1.3.1 // indirect
	github.com/google/uuid v1.1.1 // indirect
	go.etcd.io/etcd v3.3.18+incompatible
	go.uber.org/zap v1.14.0 // indirect
	google.golang.org/grpc v1.27.1 // indirect
)

将google.golang.org/grpc v1.27.1 // indirect   的版本改成google.golang.org/grpc v1.26.0

//使用go mod download 命令下载
$go mod download 
//下载完成后执行go build
$go build
$./xxx.exe  //执行文件
//输出结果

./67etcd_demo.exe
connect to etcd success
{"level":"warn","ts":"2020-03-10T13:26:03.610+0800","caller":"clientv3/retry_interceptor.go:61","msg":"retrying of unary invoker failed","target":"endpoint://client-6c0a9d95-9550-48a7-bba6-979f035508d3/127.0.0.1:2379","attempt":0,"error":"rpc error: code = DeadlineExceeded desc = context deadline exceeded"}
put to etcd failed, err:context deadline exceeded

//解决办法  
1.需要执行文件夹etcd-v3.4.4-windows-amd64下面的etcd.exe

 

你可能感兴趣的:(Go)