go版本升级到1.17.1后,go mod tidy 时候 etcd依赖报错:
go: common/modules/etcd imports
go.etcd.io/etcd/clientv3 tested by
go.etcd.io/etcd/clientv3.test imports
github.com/coreos/etcd/auth imports
github.com/coreos/etcd/mvcc/backend imports
github.com/coreos/bbolt: github.com/coreos/bbolt@v1.3.6: parsing go.mod:
module declares its path as: go.etcd.io/bbolt
but was required as: github.com/coreos/bbolt
于是求助于网络,很多文章比较老旧,提供办法如下(仍不能解决):
go mod init
go mod edit -replace github.com/coreos/bbolt@v1.3.4=go.etcd.io/bbolt@v1.3.4
go mod edit -replace google.golang.org/grpc@v1.29.1=google.golang.org/grpc@v1.26.0
go mod tidy
最后,经过通过升级Etcd依赖版本解决,正确方法如下:
-
更新etcd依赖引入路径
# 替换之前 import( "go.etcd.io/etcd/clientv3" ) # 替换之后 import( "go.etcd.io/etcd/client/v3" )
-
执行命令
rm go.mod go.sum go mod init main go mod tidy go build .
之后go.mod中依赖大概是:
require (
go.etcd.io/etcd/client/pkg/v3 v3.5.0 // indirect
go.etcd.io/etcd/client/v3 v3.5.0 // indirect
google.golang.org/grpc v1.38.0 // indirect
)
总结:因为etcd v3版本接口和最新的grpc兼容,所以不用再像网上历史文章那样去处理,直接替换etcd包地址即可。