处理etcd源码包编译异常

1、下载etcd包,执行go build报异常:

client\v2\example_keys_test.go:1:1: expected 'package', found '.'
client\v3\example_auth_test.go:1:1: expected 'package', found '.'
client\v3\concurrency\example_election_test.go:1:1: expected 'package', found '.'

2、尝试解决方案:

我照网上的解决方案去处理,处理完之后报另外一个错误:

replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
//在主目录下执行go.mod的replace下添加最后一行:
replace (
    go.etcd.io/etcd/api/v3 => ./api
    go.etcd.io/etcd/client/pkg/v3 => ./client/pkg
    go.etcd.io/etcd/client/v2 => ./client/v2
    go.etcd.io/etcd/client/v3 => ./client/v3
    go.etcd.io/etcd/etcdctl/v3 => ./etcdctl
    go.etcd.io/etcd/etcdutl/v3 => ./etcdutl
    go.etcd.io/etcd/pkg/v3 => ./pkg
    go.etcd.io/etcd/raft/v3 => ./raft
    go.etcd.io/etcd/server/v3 => ./server
    go.etcd.io/etcd/tests/v3 => ./tests
    google.golang.org/grpc => google.golang.org/grpc v1.26.0
)
​

之后会报执行go build后报:

client\v2\example_keys_test.go:1:1: expected 'package', found '.'
api\etcdserverpb\rpc.pb.go:18:2: missing go.sum entry for module providing package google.golang.org/grpc (imported by go.etcd.io/etcd/
tests/v3/integration); to add:
        go get go.etcd.io/etcd/tests/v3/integration@v3.5.11
api\etcdserverpb\rpc.pb.go:19:2: missing go.sum entry for module providing package google.golang.org/grpc/codes (imported by go.etcd.io
/etcd/api/v3/etcdserverpb); to add:
        go get go.etcd.io/etcd/api/v3/etcdserverpb@v3.5.11
api\etcdserverpb\rpc.pb.go:20:2: missing go.sum entry for module providing package google.golang.org/grpc/status (imported by go.etcd.i
o/etcd/api/v3/etcdserverpb); to add:
        go get go.etcd.io/etcd/api/v3/etcdserverpb@v3.5.11
client\v3\credentials\credentials.go:26:2: missing go.sum entry for module providing package google.golang.org/grpc/credentials (import
ed by go.etcd.io/etcd/client/v3); to add:
        go get go.etcd.io/etcd/client/v3@v3.5.11
client\v3\internal\resolver\resolver.go:19:2: missing go.sum entry for module providing package google.golang.org/grpc/resolver (import
ed by go.etcd.io/etcd/client/v3/internal/resolver); to add:
        go get go.etcd.io/etcd/client/v3/internal/resolver@v3.5.11
client\v3\internal\resolver\resolver.go:20:2: missing go.sum entry for module providing package google.golang.org/grpc/resolver/manual
(imported by go.etcd.io/etcd/client/v3/internal/resolver); to add:
        go get go.etcd.io/etcd/client/v3/internal/resolver@v3.5.11
client\v3\internal\resolver\resolver.go:21:2: missing go.sum entry for module providing package google.golang.org/grpc/serviceconfig (i
mported by go.etcd.io/etcd/client/v3/internal/resolver); to add:
        go get go.etcd.io/etcd/client/v3/internal/resolver@v3.5.11
client\v3\logger.go:24:2: missing go.sum entry for module providing package google.golang.org/grpc/grpclog (imported by go.etcd.io/etcd
/etcdctl/v3/ctlv3/command); to add:
        go get go.etcd.io/etcd/etcdctl/v3/ctlv3/command@v3.5.11
client\v3\client.go:35:2: missing go.sum entry for module providing package google.golang.org/grpc/keepalive (imported by go.etcd.io/et
cd/tests/v3/integration); to add:
        go get go.etcd.io/etcd/tests/v3/integration@v3.5.11
client\v3\ctx.go:22:2: missing go.sum entry for module providing package google.golang.org/grpc/metadata (imported by go.etcd.io/etcd/c
lient/v3); to add:
        go get go.etcd.io/etcd/client/v3@v3.5.11
client\v3\example_auth_test.go:1:1: expected 'package', found '.'
client\v3\concurrency\example_election_test.go:1:1: expected 'package', found '.'
C:\software\go\pkg\mod\go.opentelemetry.io\contrib\instrumentation\google.golang.org\grpc\otelgrpc@v0.46.0\interceptor.go:29:2: missing
 go.sum entry for module providing package google.golang.org/grpc/peer (imported by go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc); to
 add:
        go get go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc@v3.5.11
C:\software\go\pkg\mod\go.opentelemetry.io\contrib\instrumentation\google.golang.org\grpc\otelgrpc@v0.46.0\stats_handler.go:23:2: missi
ng go.sum entry for module providing package google.golang.org/grpc/stats (imported by go.opentelemetry.io/contrib/instrumentation/goog
le.golang.org/grpc/otelgrpc); to add:
        go get go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc@v0.46.0
pkg\grpc_testing\stub_server.go:9:2: missing go.sum entry for module providing package google.golang.org/grpc/interop/grpc_testing (imp
orted by go.etcd.io/etcd/pkg/v3/grpc_testing); to add:
        go get go.etcd.io/etcd/pkg/v3/grpc_testing@v3.5.11
server\etcdserver\api\v3rpc\grpc.go:29:2: missing go.sum entry for module providing package google.golang.org/grpc/health (imported by
go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc); to add:
        go get go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc@v3.5.11
server\etcdserver\api\v3rpc\grpc.go:30:2: missing go.sum entry for module providing package google.golang.org/grpc/health/grpc_health_v
1 (imported by go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc); to add:
        go get go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc@v3.5.11
C:\software\go\pkg\mod\go.opentelemetry.io\otel\exporters\otlp\otlptrace\otlptracegrpc@v1.20.0\internal\otlpconfig\options.go:28:2: mis
sing go.sum entry for module providing package google.golang.org/grpc/backoff (imported by go.opentelemetry.io/otel/exporters/otlp/otlp
trace/otlptracegrpc/internal/otlpconfig); to add:
        go get go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig@v1.20.0
C:\software\go\pkg\mod\go.opentelemetry.io\otel\exporters\otlp\otlptrace\otlptracegrpc@v1.20.0\internal\otlpconfig\options.go:30:2: mis
sing go.sum entry for module providing package google.golang.org/grpc/credentials/insecure (imported by go.etcd.io/etcd/server/v3/embed
); to add:
        go get go.etcd.io/etcd/server/v3/embed@v3.5.11
C:\software\go\pkg\mod\go.opentelemetry.io\otel\exporters\otlp\otlptrace\otlptracegrpc@v1.20.0\internal\otlpconfig\options.go:31:2: mis
sing go.sum entry for module providing package google.golang.org/grpc/encoding/gzip (imported by go.opentelemetry.io/otel/exporters/otl
p/otlptrace/otlptracegrpc/internal/otlpconfig); to add:
        go get go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig@v1.20.0

---------------------------
这个错误提示说明在你的项目中,有一个 `go.etcd.io/etcd/tests/v3/integration` 包导入了 `google.golang.org/grpc`,但是在你的 `go.sum` 文件中缺少了与 `google.golang.org/grpc` 相关的模块条目
go get google.golang.org/grpc@v1.26.0

之后又报,最后又提示我这个,搜了一圈之后,说是我的grpc的版本不包含当前的某个包,也就是转来转去又转回去了:

dummy.go:21:2: module go.etcd.io/etcd/client/v2 provides package go.etcd.io/etcd/client/v2 and is replaced but not required; to add it:

        go get go.etcd.io/etcd/client/v2
dummy.go:22:2: module go.etcd.io/etcd/etcdctl/v3 provides package go.etcd.io/etcd/etcdctl/v3/ctlv3/command and is replaced but not requ
ired; to add it:
        go get go.etcd.io/etcd/etcdctl/v3
dummy.go:23:2: module go.etcd.io/etcd/etcdutl/v3 provides package go.etcd.io/etcd/etcdutl/v3/etcdutl and is replaced but not required;
to add it:
        go get go.etcd.io/etcd/etcdutl/v3
dummy.go:24:2: module go.etcd.io/etcd/tests/v3 provides package go.etcd.io/etcd/tests/v3/integration and is replaced but not required;
to add it:
        go get go.etcd.io/etcd/tests/v3

3、最终解决方案:

报错的就是:

../../tests/integration/client/examples/example_keys_test.go

因为不符合go的包校验,所以build错误,我看这块确认不符合,不知道etcd官方3.5版本之后为什么会把样例测试文件分离出来,有高手看到可以评论一下:

我这块解决方式是通过,把对应路径下的代码一个一个的copy过来,处理解决:

大概有7、8个文件:

之后执行编译,则无错误异常,也不需要替换上面所谓grpc的包版本,问题得到解决:

go build
go mod tidy

  • 11
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

谷隐凡二

相识便是缘,开启技术大门

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

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

打赏作者

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

抵扣说明:

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

余额充值