liveBook · Manning

Protoc-gen-go-grpc

As explained in Learn Go with Pocket-Sized Projects

protoc-gen-go-grpc is a protoc plugin that generates Go gRPC client and server code from Protocol Buffers service definitions.

protoc-gen-go-grpc is a protoc plugin that generates Go gRPC client and server code from Protocol Buffers service definitions. It works alongside protoc-gen-go, which generates Go message types. section 10.1.2

Use it in a practical generation workflow:

  • Install the plugin with Go alongside protoc-gen-go. section 10.1.2
  • Invoke it through protoc with --go-grpc_out and optionally preserve source-relative paths with --go-grpc_opt=paths=source_relative. section 10.1.2
  • Generate service code from all .proto files while supplying an import directory with -I. section 10.1.2

Generate Go gRPC files

protoc -I=api/proto/ --go_out=api/ --go_opt=paths=source_relative --go-grpc_out=api/ --go-grpc_opt=paths=source_relative api/proto/*.proto section 10.1.2

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

Install protoc-gen-go-grpc with Go before invoking it through protoc. section 10.1.2

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains installation and compilation flags, stopping short of generated-code internals.
Examples
Uses a habits tracker, multiple .proto files, protoc commands, and generated service_grpc.pb.go output.
What it assumes
Assumes a Go module, protoc, and Protocol Buffers service definitions; teaches plugin installation and invocation.
What you can do after
Operate protoc to generate Go gRPC service files with controlled output paths and import resolution.
How it connects
Connects protoc-gen-go-grpc with protoc, Protocol Buffers, gRPC, Go, and protoc-gen-go.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.