Protocol buffer compiler
While not mandatory, gRPC applications often leverage Protocol Buffers for service definitions and data serialization. All the services in Impulse uses version 3 of the protocol buffer language (proto3).
The protocol buffer compiler, protoc, is used to compile .proto
files, which contain service and message definitions.
How to install protoc
Mac OS
Install Protocol buffer compiler, protoc
brew install protobuf
protoc --version # Ensure compiler version is 3+
Install Go plugins for the protocol compiler
cd ~
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
Update your PATH so that the protoc compiler can find the plugins:
export PATH="$PATH:$(go env GOPATH)/bin"
Compile .proto file
Regular Microservices (Depends on the go-grpc)
When compiling .proto
files from a microservice it is important to notice there is a dependency with the go-grpc
module, meaning, it needs to exist.
protoc --go_out=./generated --go_opt=paths=source_relative \
--go-grpc_out=./generated --go-grpc_opt=paths=source_relative \
grpc/*.proto --proto_path=../go-grpc --proto_path=.
Microservices with no dependencies with the go-grpc module
protoc --go_out=./generated --go_opt=paths=source_relative \
--go-grpc_out=./generated --go-grpc_opt=paths=source_relative \
grpc/*.proto --proto_path=.
From the go-grpc module:
For cases where the generic gRPC messages used by all the microservices existing in the go-grpc
module need to be updated.
protoc --go_out=./generated --go_opt=paths=source_relative \
--go-grpc_out=./generated --go-grpc_opt=paths=source_relative \
grpc/*.proto --proto_path=.
Last updated
Was this helpful?