0

Every time, I generate the code, I am getting this error:

error-image

this is my .proto file:

proto-file

the command that, I use to generate the code is:: 

protoc pb/pb.proto --go-grpc_out=./pb
Brits
  • 14,829
  • 2
  • 18
  • 31
  • You will need both `--go-grpc_out` and `--go_out` options (each option results in an output file per `.proto` and the output from the `--go-grpc_out` argument depends upon the output from the `--go_out` argument). See [the tutorial](https://grpc.io/docs/languages/go/basics/#generating-client-and-server-code). – Brits Mar 19 '22 at 07:57
  • Note: Please [don't post images](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-errors-when-asking-a-question/285557#285557) of things like `.proto` files - paste/format the text instead (and for go issues its better to post the output of `go build` rather than warnings in an IDE). – Brits Mar 19 '22 at 08:04
  • okay, yeah it's working now – Niteesh Dubey Mar 19 '22 at 19:32

2 Answers2

1

Please try this command to generate the code

protoc -I <proto-file-folder/> --go_out=plugins=grpc:<folder-to-store-generated-go-file> <proto-file-folder>/*.proto

In your case

protoc -I pb/ --go_out=plugins=grpc:pb/ pb/*.proto
Pratheesh M
  • 1,028
  • 6
  • 13
  • The `plugins` argument is outdated and I don't believe it works with recent versions of `google.golang.org/protobuf/cmd/protoc-gen-go` (see notes under [this question](https://stackoverflow.com/questions/60578892/protoc-gen-go-grpc-program-not-found-or-is-not-executable)) – Brits Mar 19 '22 at 07:59
-1

As per the tutorial you need to use pass protoc two parameters; --go_out and --go-grpc_out (you probably also want to pass the associated _opt parameters):

protoc --go_out=. --go_opt=paths=source_relative \
    --go-grpc_out=. --go-grpc_opt=paths=source_relative \
    routeguide/route_guide.proto

In your case this translates to:

protoc pb/pb.proto --go_out=./pb  --go-grpc_out=./pb

The reason for the error that you were seeing is that --go-grpc_out tells protoc to run protoc-gen-go-grpc (from google.golang.org/grpc/cmd/protoc-gen-go-grpc). This executable only generates the gRPC specific code; it assumes that the code required to translate between protoBuf and Go structures has already been created (and this is done by protoc-gen-go which is triggered by the --go_out).

Brits
  • 14,829
  • 2
  • 18
  • 31