Go-Micro注册服务到ETCD时报错:undefined: resolver.BuildOption、undefined: balancer.PickOptions

使用Go-Micro注册服务到ETCD时报错如下:

# 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

原因:
ETCD中使用的旧版本gRPC库与最新版本的gRPC库不兼容,需要在go.mod中将gRPC替换为v1.26.0版本的即可。

# go.mod
module MicroProject

go 1.14

require (
	github.com/gin-contrib/zap v0.0.1
	github.com/gin-gonic/gin v1.6.2
	github.com/go-sql-driver/mysql v1.5.0
	github.com/golang/protobuf v1.4.1
	github.com/grpc-ecosystem/grpc-gateway v1.14.4 // indirect
	github.com/jinzhu/gorm v1.9.12
	github.com/micro/go-micro/v2 v2.6.0
	github.com/natefinch/lumberjack v2.0.0+incompatible
	github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
	github.com/nicksnyder/go-i18n v1.10.1
	github.com/pelletier/go-toml v1.7.0 // indirect
	github.com/satori/go.uuid v1.2.0
	go.uber.org/zap v1.14.1
	golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59
	golang.org/x/net v0.0.0-20200505041828-1ed23360d12c
	golang.org/x/sys v0.0.0-20200501145240-bc7a7d42d5c3 // indirect
	google.golang.org/genproto v0.0.0-20191216164720-4f79533eabd1
	google.golang.org/protobuf v1.22.0
	gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
)

# 替换为v1.26.0版本的gRPC库
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0

参考链接

  • 煎鱼大佬提的Issues: clientv3: grpc-go (v1.27.0) made API changes to balancer / resolver. #11563

你可能感兴趣的:(grpc)