Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How am I supposed to use protoc-gen-go-grpc?

I am trying to generate Go code for some Protocol Buffers as well as a gRPC service.

In the past I have used https://github.com/golang/protobuf with a generate command that looked something like this:

//go:generate protoc --proto_path=. --go-out=. --go_opt=paths=source_relative <file>.proto
//go:generate protoc --proto_path=. --go_grpc_out=. --go_grpc_opt=paths=source_relative <file>.proto

This method worked just fine, but the repo has since been superceded by google.golang.org/protobuf and google.golang.org/grpc.

From what I've read, this was an intentional split to separate the protobuf and gRPC project release cycles.

Using the new repositories, I installed the tools like this:

go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest

Both tools are installed, and are visible on the path. The problem that I'm encountering is that protoc or protoc-gen-go is looking for the older tool - protoc-gen-go_grpc. Note the underscore.

I have been reading all the documentation and Github issues that I can find, and haven't yet been able to figure out how I am meant to use the new protoc-gen-go-grpc. Note the dash.

$ echo $GOPATH
/Users/<username>/dev/go

$ echo $GOBIN
/Users/<username>/dev/go/bin

$ which protoc
/opt/homebrew/bin/protoc

$ which protoc-gen-go
/Users/<username>/dev/go/bin/protoc-gen-go

$ which protoc-gen-go_grpc
protoc-gen-go_grpc not found

$ which protoc-gen-go-grpc
/Users/<username>/dev/go/bin/protoc-gen-go-grpc
like image 955
Nick Corin Avatar asked Dec 04 '25 06:12

Nick Corin


1 Answers

My issue was so simple to fix, but darn annoying to find.

When running protoc, using the --go_grpc_out flag looks for protoc-gen-go_grpc.

When running protoc, using --go-grpc_out flag looks for protoc-gen-go-grpc.

It seems that instead of protoc having well defined, documented flags, and erroring when an incorrect flag is provided they're using the flags to determine which plugin to use. If you misspell the flag, it looks for the wrong plugin.

like image 56
Nick Corin Avatar answered Dec 07 '25 01:12

Nick Corin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!