-
Notifications
You must be signed in to change notification settings - Fork 1.6k
From multiple proto files, generate only one file.pb.go #681
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi, thanks for the report. This is a duplicate of #39. It's something we may want to address in the near future (no guarantees), but there are currently other protobuf items we're working on. So feel free to subscribe to that issue. |
Thanks for the fast reply :) Sorry I didn't notice it when I was searching in the issues.. However, it seems that people are looking for merging different packages when I am trying to just merge different proto files of the same package into only one Am I wrong? Max |
Sorry. I misread your post. You actually want the contents of all three |
One of the assumptions made by The best you can do today is to do
|
Ok thank you first for reopening :) It's just about readability, tbh the 3 proto files could be just one, I just prefere to separate my class (or model) from my methods/functions I will give it a try asap and come back to you Thanks Max |
I tested this out and it should satisfy what you want:
File "test.proto" has: syntax = "proto2";
import public "foo/foo.proto";
import public "bar/bar.proto";
message MyMessage {
optional FooMessage foo = 1;
optional BarMessage bar = 2;
} File "foo.proto" has: syntax = "proto2";
option go_package = "github.com/user/project/foo";
message FooMessage { optional string f = 1; } File "bar.proto" has: syntax = "proto2";
option go_package = "github.com/user/project/bar";
message BarMessage { optional string f = 1; } When compiling with package test
import bar "github.com/user/project/bar"
import foo "github.com/user/project/foo"
// FooMessage from public import foo/foo.proto
type FooMessage = foo.FooMessage
// BarMessage from public import bar/bar.proto
type BarMessage = bar.BarMessage
type MyMessage struct {
Foo *foo.FooMessage `protobuf:"bytes,1,opt,name=foo" json:"foo,omitempty"`
Bar *bar.BarMessage `protobuf:"bytes,2,opt,name=bar" json:"bar,omitempty"`
...
} As you can see, this generates The caveats of this:
Since this kinda accomplishes what you want, I'm going to close this issue as a mixture of "working as intended" and "workaround available". I don't think we would ever provide first-class support for the feature since that would probably interact poorly with #39. |
Hey ! Ok but import public doesn't work, so why are you using it?
libprotoc 3.5.1
|
"Ignoring public import" means that you're doing an |
If your import paths are sufficiently simple, you may be hitting #646. I think it will work if you put area.proto and place.proto in sub-directories. |
@neild But neither "import public" or "import" works if I don't compile as well the other protofile.. The thing is, I have 3 protofile in the example and I want only on generated file, either if I import or not, only the main file is generated, but not the 2 others, I have to add them to the CLI which generates me 3 files instead of just one @dsnet They are part of the same package actually :/ |
Each input |
That's why it's weird to me... It means that, if I have an API in Go, and my client in Android, I have to pass all of my proto file (the exchanged one between mobile and API) to my client... If I have 25 classes, I need to duplicate there 25classes file in Android and Go? Then generate the pg.go and the pb.java |
Hey folks !
I am creating my first service in go with protobuf and I was wondering if I could generate only one
task.pg.go
from my 3 different protofiles?They are in the same package, referencing the same output package.
Task
imports the 2 others at the beginning of the file.I then generate my task.pb.go from
protoc task.proto --go_out=plugins=grpc:.
. It works, however, the pb file won't contain the Date messages and the Content messages.In fact, the output will contains the
rpc
functions but not the messages from the other files.The generated protofile
task.pb.go
contains the definitions, so the methods are found by my main.go file, but the messages cannot be find.Thanks for any help
PS: feel free to ask more details if you need to
Max
The text was updated successfully, but these errors were encountered: