gogo.proto : File not found

标签 go protocol-buffers

协议(protocol) --gogofaster_out=。图片.proto

我收到此错误消息

/home/abc/src/github.com/gogo/protobuf/gogoproto/gogo.proto: File not found.

image.proto: Import "/home/abc/src/github.com/gogo/protobuf/gogoproto/gogo.proto" was not found or had errors.

文件肯定在那里。我可以从错误中报告的路径到达它。

我的原型(prototype)文件是这样的:

package image;

import "/home/abc/src/github.com/gogo/protobuf/gogoproto/gogo.proto";

message Frame {
required bool fragment = 1; 
required int32  fragmentID = 2; 
required bool lastFragment = 3; 
required bytes data = 4;
}

我在原始文件所在的目录中有一个Makefile。看起来像这样:

regenerate:
--proto_path=../../github.com/gogo/protobuf/gogoproto:../../github.com/gogo/protobuf/protobuf/google/protobuf:. --gogofaster_out=. *.proto

如何解决路径错误?

最佳答案

作为in this issue ,您可以尝试仅导入相对路径:

import "github.com/gogo/protobuf/gogoproto/gogo.proto";

首先确保GOPATH设置为/home/abc

我提到 protobuf PR 241 ,其中 makefile 定义了要使用的 PATH:

regenerate: 
  protoc-min-version --version="3.0.0" 
    --proto_path=$(GOPATH)/src/image:
                 $(GOPATH)/src/github.com/go‌​go/protobuf/protobuf‌​:
                 $(GOPATH)/src/githu‌​b.com/gogo/protobuf/‌​protobuf/google/prot‌​obuf:
                 . --gogo_out=. *.proto 

OP 提及 this thread ,它指出:

The dependencies call other dependencies in "google/protobuf/", so these need to be in the path correctly also.
The errors are pretty misleading

Also when using gogoproto extensions you should use gogofast_out.
gofast_out is only for when you are not using any extensions, but want some extra speed.
gogofast_out / gofast_out has no side effects.
gogofaster_out makes most fields nullable=false.

关于gogo.proto : File not found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43026449/

相关文章:

go - Protocol Buffer 文件中使用的 go_package 选项是什么?

google-app-engine - 继续 Google App Engine 返回错误 : API error 1 (mail: INTERNAL_ERROR): Internal error

serialization - 在 protobuf-net 中,有没有办法指定在序列化/反序列化给定类型时要使用的自定义方法?

Android 和 Protocol Buffer

c - 使用 ZeroMQ 和 ProtocolBuffers 发送结构

javascript - 如何从 HTML 中的嵌入式 Javascript 中抓取值?

go - golang中根据环境配置数据库细节

google-app-engine - 如何判断我是否在 google app engine/go 上本地运行

c# - 从 C# 读取 protobuf3 自定义选项

json - JSON RPC 与 HTTP2 与 grpc 有什么区别?