go-zero 启动报错 cannot use &errPicker literal (type *errPicker) as type Picker in return argument:

在使用Go语言开发时,遇到了Etcd客户端库与gRPC库之间的版本不兼容问题,导致编译错误。错误信息涉及到`go.etcd.io/etcd/clientv3/balancer/picker`和`github.com/tal-tech/go-zero/zrpc/internal/balancer/p2c`等模块。解决方案是在go.mod文件末尾添加一行`replace google.golang.org/grpc => google.golang.org/grpcv1.29.1`来替换gRPC的版本。这表明项目中的gRPC版本需要与Etcd和zrpc库兼容的特定版本。

# go.etcd.io/etcd/clientv3/balancer/picker
E:\Go\pkg\mod\go.etcd.io\etcd@v0.0.0-20200402134248-51bdeb39e698\clientv3\balancer\picker\err.go:25:9: cannot use &errPicker literal (type *errPicker) as type Picker in return argument:
        *errPicker does not implement Picker (wrong type for Pick method)
                have Pick(context.Context, balancer.PickInfo) (balancer.SubConn, func(balancer.DoneInfo), error)
                want Pick(balancer.PickInfo) (balancer.PickResult, error)
E:\Go\pkg\mod\go.etcd.io\etcd@v0.0.0-20200402134248-51bdeb39e698\clientv3\balancer\picker\roundrobin_balanced.go:33:9: cannot use &rrBalanced literal (type *rrBalanced) as type Picker in return argument:
        *rrBalanced does not implement Picker (wrong type for Pick method)
                have Pick(context.Context, balancer.PickInfo) (balancer.SubConn, func(balancer.DoneInfo), error)
                want Pick(balancer.PickInfo) (balancer.PickResult, error)
# github.com/tal-tech/go-zero/zrpc/internal/balancer/p2c
E:\Go\pkg\mod\github.com\tal-tech\go-zero@v1.1.5\zrpc\internal\balancer\p2c\p2c.go:43:32: not enough arguments in call to base.NewBalancerBuilder
        have (string, *p2cPickerBuilder)
        want (string, base.PickerBuilder, base.Config)
E:\Go\pkg\mod\github.com\tal-tech\go-zero@v1.1.5\zrpc\internal\balancer\p2c\p2c.go:60:9: cannot use &p2cPicker literal (type *p2cPicker) as type balancer.Picker in return argument:
        *p2cPicker does not implement balancer.Picker (wrong type for Pick method)
                have Pick(context.Context, balancer.PickInfo) (balancer.SubConn, func(balancer.DoneInfo), error)
                want Pick(balancer.PickInfo) (balancer.PickResult, error)
 

 

原因就是ETCD的毒

解决办法

go.mod 最后添加一行

replace google.golang.org/grpc => google.golang.org/grpc v1.29.1

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

JwCode

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值