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

将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..

图片转代码服务由CSDN问答提供 功能建议

我正在使用支持模块的Golang 1.11,因此我的项目 $ GOPATH

我要编译 proto 文件,

我的文件结构< / p>

”在此处输入图片说明“


我的 TaskInfo.proto

  syntax =“ proto3”; 
package chaochaogege.filecatcher.common; 
 
option go_package =“ common”; 
 
import“ chaochaogege.com/filecatcher/  common / ChunkInfo.proto“; 
 
message TaskInfo {
字符串名称= 1; 
字符串storePath = 2; 
 uint32 workerNum = 3; 
 uint32 totalSize = 4; 
重复chaochaogege.filecatcher.common。  ChunkInfo chunkInfo = 5; 
} 
   
 
 

ChunkInfo.proto

 语法 =“ proto3”; 
package chaochaogege.filecatcher.common; 
 
option go_package =“ common”; 
 
mess 年龄ChunkInfo {
 uint32 startBytes = 1; 
 uint32 endBytes = 2; 
 uint32 totalBytes = 3; 
 uint32已下载= 4; 
 uint32 orderId = 5; 
 
} 
  <  /pre>


go.mod

module chaochaogege.com/filecatcher

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

当我运行时(在文件收集器/公共目录中)

 <  code> protoc --go_out =。/ TaskInfo.proto 
   
 
 

protoc说:

  chaochaogege.com/  filecatcher / common / ChunkInfo.proto:找不到文件。TaskInfo.proto:找不到导入的“ chaochaogege.com/filecatcher/common/ChunkInfo.proto”或有错误。
TaskInfo.proto:13:14:“ chaochaogege.filecatcher  .common.ChunkInfo”未定义。
   
 
 

我已经用Google搜索过,但是所有问题都与go模块无关

Did 我使用错误的导入路径或我的配置不正确?

如果Stackoverflow无法回答我的问题,我认为这是一个错误。 我应该去Github问题报告。. \ n

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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/

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题