D
D
DeYuro2021-08-01 22:25:11
go
DeYuro, 2021-08-01 22:25:11

How to generate protoc --go-grpc_out code in scope of generated --go_out code?

In old projects I used the old proto-gen-go which supported plugins and allowed to generate serialized data and a client / server in one pb.go file

, now I use protoc-gen-go v1.27.1 which, as I understand it, does not support plugins and requires explicit --go-grpc_out flag to generate client\server

according to 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 get this file tree
generated
|_proto
  |_v1
  |_dummy
  | |_foo_grpc.pb.go //package dummy
  |_foo.pb.go //package dummy


Due to the fact that foo_grpc.pb.go was generated in a separate dummy folder, its functions do not see variables from foo.pb.go - it is solved by moving the file to 1 level.

What am I doing wrong? Is there a way to generate 1 file like before?

Also is there a way to use old flags like --go_out=import_path=" and specify package via M in cmd without slashes and go_options in protofile like this:
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;
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question