0

In previos products i use old protoc-gen-go which allow 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 will not allow plugins and demand to use go-grpc_out flag for client\server code

Follow this 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

i got

generated
|_proto
  |_v1
  |_dummy
  | |_foo_grpc.pb.go //package dummy
  |_foo.pb.go //package dummy

Because of created "dummy" folder foo_grpc.pb.go functions do not see Request and Response which generated in foo.pb.go

What i am doing wrong? Is there is option to generate one file as before? It will be work properly after move foo_grpc.pb.go on same level with foo.pb.go.

Also is there 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;
}
DeYuro
  • 65
  • 5
  • Add a `--go-grpc_opt=paths=source_relative` (or, my preferred option, `go-grpc_opt=module=MODULEPATH`). – Brits Aug 01 '21 at 19:46
  • Omg... thanks! Where can i find all flags and possible values? – DeYuro Aug 01 '21 at 19:57
  • Had a quick look for this myself before responding and could not find a document that covers this for gRPC. However the flags are the same as for the proto plugin so [that documentation](https://developers.google.com/protocol-buffers/docs/reference/go-generated) helps (the same applies to `grpc-gateway_opt` as [summarised in this answer](https://stackoverflow.com/a/66214293/11810946)). – Brits Aug 01 '21 at 20:14

1 Answers1

3

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).

Brits
  • 14,829
  • 2
  • 18
  • 31