protoc-gen-go is a protoc plugin that turns Protocol Buffers message definitions into Go source files. protoc-gen-go-grpc performs the corresponding gRPC service generation. section 10.1.2
A practical generation workflow:
- Install protoc through a system package manager, then install both Go plugins with go install. section 10.1.2
- Pass --go_out and --go_opt=paths=source_relative to generate files beside the source tree rather than recreating the module path. section 10.1.2
- Compile all .proto files with -I=api/proto/ so service.proto can resolve imports from habit.proto. section 10.1.2
- Add --go-grpc_out and --go-grpc_opt for service stubs, optionally disabling required unimplemented servers. section 10.1.2
Generate the API
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
> apt install -y protobuf-compiler #Linux > brew install protobuf #Mac
Use the supplied command listings to compare installation, output-path, import-path, gRPC, and go:generate variants. section 10.1.2
