Using protoc-gen-go creates a .pb.go that imports google/golang but can't find package

huangapple go评论88阅读模式
英文:

Using protoc-gen-go creates a .pb.go that imports google/golang but can't find package

问题

我正在使用protoc-gen-goCProtocol Buffers编译成Golang,这个工具非常好用,我几乎可以使用go install命令安装包,但是我遇到了以下错误:

cannot find package "google/protobuf"

但是我无法找到这个包的下载地址,有人可以告诉我该怎么处理吗?谢谢。

我按照这里的所有步骤进行操作,然后运行protoc --go_out=. *.proto命令生成了所有的文件,但是导入proto文件时出错了。

英文:

I'm using protoc-gen-go to compile C Protocol Buffers into Golang which works great and I can almost go install the package but I get this error:

cannot find package "google/protobuf"

but I cannot find this package anywhere to download, can anybody tell me what I should do with this? Thanks.

I'm following all steps to doing it from here

then I run protoc --go_out=. *.proto and I get all my files, but the wrong proto import

答案1

得分: 1

根据@poopoothegoriall的说法,请使用来自GitHub的protobuf,而不是code-google。生成的.pb.go文件将导入"github.com/golang/protobuf/proto"

更新
这是我的步骤:

  1. 使用make install命令安装项目https://github.com/google/protobuf.git。
  2. 使用go get命令获取https://github.com/golang/protobuf。
  3. 使用protoc --go_out=. xxx.proto命令生成Go源代码。
英文:

as @poopoothegoriall said, please use the protobuf from github, other than code-google. the generated .pb.go file will import "github.com/golang/protobuf/proto"

UPDATE
this is my steps:

  1. make install project https://github.com/google/protobuf.git
  2. go get https://github.com/golang/protobuf
  3. generate the go source by protoc --go_out=. xxx.proto

huangapple
  • 本文由 发表于 2015年11月26日 11:19:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/33930028.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定