protoc & protoc-gen-go安装
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.
- mac OS
- Enter the protobuf release page and select the compressed package file suitable for your operating system
- Unzip and enter
protoc-3.14.0-osx-x86_64
- Move the started
protoc
binary 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. - Verify the installation result
With goctl versions greater than 1.2.1, there is no need to install the
protoc-gen-go
plugin, because after that version, goctl has been implemented as a plugin for , and goctl will automatically create a symbolic linkprotoc-gen-goctl
togoctl
, which will generate pb.go according to the following logic.
- detect the existence of
protoc-gen-go
plugin in the environment variable, if not, the generation process is finished - generate pb.go based on the detected plugins
- Move protoc-gen-go to any path where environment variables are added, such as
$GOPATH/bin
, because the binary itself aftergo get
is in the directory, so just make sure your$GOPATH/bin
can be in the environment variable.