dtsi9484 2018-10-09 09:28
浏览 458
已采纳

将Golang1.11与模块一起使用时,Protobuf导入“找不到文件”

I'm use Golang 1.11 with module support, So my project is not put in $GOPATH

I am want to compile proto file,

My files structure

enter image description here


my TaskInfo.proto

syntax = "proto3";
package chaochaogege.filecatcher.common;

option go_package = "common";

import "chaochaogege.com/filecatcher/common/ChunkInfo.proto";

message TaskInfo{
    string name = 1;
    string storePath = 2;
    uint32 workersNum = 3;
    uint32 totalSize = 4;
    repeated chaochaogege.filecatcher.common.ChunkInfo chunkInfo = 5;
}

ChunkInfo.proto

syntax = "proto3";
package chaochaogege.filecatcher.common;

option go_package = "common";

message ChunkInfo{
    uint32 startBytes = 1;
    uint32 endBytes = 2;
    uint32 totalBytes = 3;
    uint32 downloaded = 4;
    uint32 orderId = 5;

}

go.mod

module chaochaogege.com/filecatcher

require (
  github.com/golang/protobuf v1.2.0
)

When I run follow (in filecatcher/common directory)

protoc --go_out=./ TaskInfo.proto

protoc said:

chaochaogege.com/filecatcher/common/ChunkInfo.proto: File not found.TaskInfo.proto: Import "chaochaogege.com/filecatcher/common/ChunkInfo.proto" was not found or had errors.
TaskInfo.proto:13:14: "chaochaogege.filecatcher.common.ChunkInfo" is notdefined.

I have googled, But all of questions are not about go module

Did I use wrong import path or My config is not correct?

If Stackoverflow cannot anwser my question, I think it's a bug. I should go to Github issue for report..

  • 写回答

1条回答 默认 最新

  • douxing2156 2018-10-10 03:28
    关注

    Looks like you are mixing up paths

    Your import path is

    import "chaochaogege.com/filecatcher/common/ChunkInfo.proto";

    If you want to run protoc from inside filecatcher/common then you would want to shorten your import to just import "ChunkInfo.proto" and run the command you are trying to run now. It will work.

    But if you want to keep your import statement as it is, then you would have to navigate to the parent directory of chaochaogege.com and run the following command from there as follows:

    protoc -I chaochaogege.com/filecatcher/common/ chaogege.com/filecatcher/common/ChunkInfo.proto --go_out=chaochaogege.com/filecatcher/common/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 矩阵加法的规则是两个矩阵中对应位置的数的绝对值进行加和
  • ¥15 活动选择题。最多可以参加几个项目?
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)
  • ¥20 怎么在stm32门禁成品上增加查询记录功能
  • ¥15 Source insight编写代码后使用CCS5.2版本import之后,代码跳到注释行里面
  • ¥50 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀