In previous products, I used the old protoc-gen-go
, which allowed me to use plugins and generate serialization/deserialization and gRPC client/server in same .pb file.
As far I understand, protoc-gen-go v1.27.1 does not allow plugins and requires the use of go-grpc_out flag for client\server code.
When I run the following command:
protoc -I /usr/local/include -I $PWD/api/dummy-proto --go_out=generated --go-grpc_out=generated --go_opt=paths=source_relative proto/v1/foo.proto
What I get is the following:
generated
|_proto
|_v1
|_dummy
| |_foo_grpc.pb.go //package dummy
|_foo.pb.go //package dummy
Because of the created "dummy/" folder, foo_grpc.pb.go file does not see Request
and Response
messages that were generated in foo.pb.go.
What am I doing wrong? Is there is an option to generate one file as before? It will work properly after moveing foo_grpc.pb.go to same level with foo.pb.go.
Also is it is possible to use old flag like --go_out=import_path="
and declare package with M without slashes and without go_options in proto like -go_out=import_path=grpc_v1_proto,M$PWD/proto/v1/foo.proto=grpc_v1_proto"
foo.proto
syntax = "proto3";
package dummy.v1.foo;
option go_package = "proto/v1/dummy";
import "proto/v1/structures.proto";
service FooService {
rpc reverse(ReverseRequest) returns (ReverseResponse);
rpc getBar(GetBarRequest) returns (GetBarResponse);
}
message ReverseRequest {
string text = 1;
}
message ReverseResponse {
string reversed_text = 1;
}
message GetBarRequest {
}
message GetBarResponse {
structures.Bar bar = 1;
}
As per the comments you need to add --go-grpc_opt=paths=source_relative
. This is covered in the basics tutorial (but that really just gives the command without much detail).
protoc-gen-go-grpc
uses code shared with protoc-gen-go
to process most of these options so the documentation for Go Generated Code will probably answer your questions (just change go_opt
to go-grpc_opt
).