【问题标题】:Importing proto files and compiling导入 proto 文件并编译
【发布时间】:2020-01-17 07:51:58
【问题描述】:

我在以下目录中有两个 proto 文件 -

parsers/
   > flights/
       > flights_proto/
           > flights.proto
           > flights.pb.go
   > flightspostbooking
       > flights_postbooking_proto/
           > flights_postbooking.proto
           > flights_postbooking.pb.go

以下是 proto 文件的内容 -

flights.proto
=============

package "flights_proto";

message Flight {
   ...
}

flights_postbooking.proto
=========================

package "flights_postbooking_proto"
import "flights_proto/flights.proto"

message Cancel {
    Flight flight = 1;
    ...
}

我无法弄清楚如何编译 flights_postbooking.proto 以生成 pb.go 文件。

我尝试从parsers 目录执行以下操作。

protoc --proto_path=flightspostbooking/flights_postbooking_proto --proto_path=flights/flights_proto flightspostbooking/flights_postbooking_proto/flights_postbooking.proto --go_out=plugins:flights_postbooking_proto

但我收到一个错误,flights_proto/flights.proto: File not found

【问题讨论】:

    标签: go protocol-buffers


    【解决方案1】:

    parsers 目录运行protoc,并为您的原型文件使用基目录,即.

    protoc --proto_path=. --go_out=plugins=grpc:flightpostbooking/flights_postbooking_proto flightpostbooking/flights_postbooking_proto/flights_postbooking.proto
    

    由于您有 parsers 目录作为您的基础,您的导入应该是:

    import "flights/flights_proto/flights.proto"
    

    关键是使用相对于您的proto_path 的导入路径。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 2020-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多