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
