英文:
protoc generate golang code from two proto files which belong to different package
问题
我有两个proto源文件,位于同一个文件夹中,假设为:
第一个是 foo.proto
syntax = "proto3";
package foo;
第二个是 bar.proto
,需要导入 foo.proto
syntax = "proto3";
import "foo.proto";
package bar;
你可以看到它们有不同的包名。当我使用protoc逐个生成它们时(当然先生成foo.proto),我得到了两个生成的golang文件,但我必须将它们放入两个目录中(你不能将不同包名的文件放在同一个目录中,golang不支持):
foo/foo.pb.go
bar/bar.pb.go
但是在 bar.pb.go
中,导入路径使用的是本地导入路径,类似于:
import foo ".";
我尝试了一些protoc提供的选项,但没有使其工作,有什么建议吗?
英文:
I have two proto src file, in same folder, let's say:
the 1st one is foo.proto
syntax = "proto3";
package foo;
the second is bar.proto
, which need import foo.proto
syntax = "proto3";
import "foo.proto";
package bar;
you can see they have different package name, when I use protoc to generate them one by one, (foo.proto as the 1st of cause), I have two golang file generated, but I have to put them into 2 directory (you can't put different package name file inside same directory, golang )
foo/foo.pb.go
bar/bar.pb.go
but inside bar.pb.go
the import are using local import path, which is like
import foo "."
I'm tweeking several options which protoc provided, but didn't make this work, any suggestion?
答案1
得分: 1
我相信添加option go_package
应该是正确的解决方案。
英文:
I believe add option go_package
should be the correct solution
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论