【问题标题】:File not found error while importing protos导入 protos 时找不到文件错误
【发布时间】:2021-09-16 06:11:12
【问题描述】:

我正在尝试使用 Nighthawk 项目中的 this proto 创建 Go gRPC 客户端代码,但出现此错误:

user@computer:~/Code/nighthawk$ protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative api/client/output.proto 
envoy/config/core/v3/base.proto: File not found.
envoy/config/metrics/v3/stats.proto: File not found.
envoy/extensions/transport_sockets/tls/v3/cert.proto: File not found.
envoy/config/core/v3/extension.proto: File not found.
validate/validate.proto: File not found.
api/client/options.proto: Import "envoy/config/core/v3/base.proto" was not found or had errors.
api/client/options.proto: Import "envoy/config/metrics/v3/stats.proto" was not found or had errors.
api/client/options.proto: Import "envoy/extensions/transport_sockets/tls/v3/cert.proto" was not found or had errors.
api/client/options.proto: Import "envoy/config/core/v3/extension.proto" was not found or had errors.
api/client/options.proto: Import "validate/validate.proto" was not found or had errors.
api/client/options.proto:16:3: "envoy.config.core.v3.RequestMethod" is not defined.
api/client/options.proto:17:12: "envoy.config.core.v3.HeaderValueOption" is not defined.
api/client/options.proto:186:5: "envoy.config.core.v3.TypedExtensionConfig" is not defined.
api/client/options.proto:190:3: "envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext" is not defined.
api/client/options.proto:253:3: "envoy.config.core.v3.TransportSocket" is not defined.
api/client/options.proto:259:12: "envoy.config.metrics.v3.StatsSink" is not defined.
api/client/output.proto: Import "envoy/config/core/v3/base.proto" was not found or had errors.
api/client/output.proto: Import "api/client/options.proto" was not found or had errors.
api/client/output.proto:57:3: "nighthawk.client.CommandLineOptions" is not defined.
api/client/output.proto:59:3: "envoy.config.core.v3.BuildVersion" is not defined.

我看到这些原型是在 Envoy 的存储库 here 中定义的。

如何导入这些以便生成客户端代码?

这个命令是什么?我错过了什么吗?

【问题讨论】:

    标签: protocol-buffers grpc envoyproxy


    【解决方案1】:

    通常,您不应该从其他人的 .proto 文件构建自己的 .pb.go 文件。如果在单个二进制文件中发现同一个 proto 包的多个定义,Go 会恐慌,因此每个发布的 .proto 文件理想情况下还应该在中心位置提供 .pb.go 文件。如果夜鹰不是这种情况,那么您仍然可以自己构建它。您需要下载 Envoy 依赖项并通过 -I 参数引用它们。

    【讨论】:

    • 是的,我正在尝试。 Nighthawk 夜鹰不提供 Go 存根。所以我必须手动从原型生成它。因此,下载所有依赖于此处的原型并通过 -I 标志传递其路径是做到这一点的直接方法吗?我还看到了这个工具:来自 Envoy 的 github.com/envoyproxy/protoc-gen-validate。这怎么适合这里?我应该在某处使用它来创建 Go 存根吗?
    • 是的,-I 标志应该简单明了,并且是正确的做法。对于protoc-gen-validate,我认为您无需担心。它应该是构建依赖原型不需要的扩展。您不应该自己构建特使原型;你应该改用 go-control-plane repo 的版本。
    • 谢谢。让我检查一下,看看它是否有效。
    猜你喜欢
    • 2016-11-23
    • 1970-01-01
    • 2019-05-03
    • 2018-02-23
    • 1970-01-01
    • 2020-01-14
    • 2019-09-22
    • 2020-10-24
    • 2019-08-05
    相关资源
    最近更新 更多