Go语言 etcd/clientv3报错: etcd undefined: resolver.BuildOptio 问题解决思路

故障描述

github.com/coreos/etcd/clientv3

..\..\github.com\coreos\etcd\clientv3\auth.go:125:72: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.AuthEnable
..\..\github.com\coreos\etcd\clientv3\auth.go:130:74: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.AuthDisable
..\..\github.com\coreos\etcd\clientv3\auth.go:135:72: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.AuthStatus
..\..\github.com\coreos\etcd\clientv3\auth.go:140:152: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserAdd
..\..\github.com\coreos\etcd\clientv3\auth.go:145:144: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserAdd
..\..\github.com\coreos\etcd\clientv3\auth.go:150:86: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserDelete
..\..\github.com\coreos\etcd\clientv3\auth.go:155:122: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserChangePassword
..\..\github.com\coreos\etcd\clientv3\auth.go:160:104: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserGrantRole
..\..\github.com\coreos\etcd\clientv3\auth.go:165:80: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserGet
..\..\github.com\coreos\etcd\clientv3\auth.go:170:72: cannot use auth.callOpts (type []"github.com/coreos/etcd/vendor/google.golang.org/grpc".CallOption) as type []"go.etcd.io/etcd/vendor/google.golang.org/grpc".CallOption in argument to auth.remote.UserList
..\..\github.com\coreos\etcd\clientv3\auth.go:170:72: too many errors

go语言版本

go version
go version go1.14 linux/amd64

经过测试,在macOS,Windows,Linux上都有这个问题

添加包管理器go mod

module goAgent
go 1.14

require (
    github.com/Shopify/sarama v1.26.1
    github.com/coreos/etcd v3.3.18+incompatible // indirect
    github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf // indirect
    github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f // indirect
    github.com/go-ini/ini v1.52.0
    github.com/gogo/protobuf v1.3.1 // indirect
    github.com/google/uuid v1.1.1 // indirect
    github.com/hpcloud/tail v1.0.0
    go.etcd.io/etcd v3.3.18+incompatible
    go.uber.org/zap v1.14.0 // indirect
    google.golang.org/grpc v1.27.1 // indirect
    gopkg.in/fsnotify.v1 v1.4.7 // indirect
    gopkg.in/ini.v1 v1.52.0
    gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
    )

主要错误原因: 在安装go get go.etcd.io/etcd/clientv3时出错

错误信息:

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

解决方法

将grpc版本替换成v1.26.0版本

具体步骤

修改依赖为v1.26.0

go mod edit -require=google.golang.org/grpc@v1.26.0

下载v1.26.0版本的grpc

go get -u -x google.golang.org/grpc@v1.26.0

重新构建运行程序

go build

大功告成!

你可能感兴趣的:(Go语言 etcd/clientv3报错: etcd undefined: resolver.BuildOptio 问题解决思路)