protoc is a tool written in C++, which can translate proto files into codes in the specified language. In the go-zero microservices, we use grpc to communicate between services, and the writing of grpc requires the use of protoc and the plug-in protoc-gen-go that translates into go language rpc stub code.
Demonstration environment of this document
- mac OS
Enter the protobuf release page and select the compressed package file suitable for your operating system
protoc-3.14.0-osx-x86_64$ cd protoc-3.14.0-osx-x86_64/bin
Move the started
protocbinary file to any path added to the environment variable, such as
$GOPATH/bin. It is not recommended putting it directly with the next path of the system.$ mv protoc $GOPATH/bin
$GOPATH is the actual folder address of your local machine
Verify the installation result$ protoc --versionlibprotoc 3.14.0
Windows may report an error,
A required privilege is not held by the client., because goctl needs to be run
as administrator under Windows.
The reason is that goctl needs to be run "as administrator" under Windows.
- Download and install
protoc-gen-go$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
protoc-gen-go installation failed, please read Error