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 => ./apigo.etcd.io/etcd/client/pkg/v3 => ./client/pkggo.etcd.io/etcd/client/v2 => ./client/v2go.etcd.io/etcd/client/v3 => ./client/v3go.etcd.io/etcd/etcdctl/v3 => ./etcdctlgo.etcd.io/etcd/etcdutl/v3 => ./etcdutlgo.etcd.io/etcd/pkg/v3 => ./pkggo.etcd.io/etcd/raft/v3 => ./raftgo.etcd.io/etcd/server/v3 => ./servergo.etcd.io/etcd/tests/v3 => ./testsgoogle.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: missinggo.sum entry for module providing package google.golang.org/grpc/peer (imported by go.etcd.io/etcd/server/v3/etcdserver/api/v3rpc); toadd: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