protoc是一款用C++編寫的工具,其可以將proto文件翻譯為指定語言的代碼。在go-zero的微服務(wù)中,我們采用grpc進(jìn)行服務(wù)間的通信,而grpc的編寫就需要用到protoc和翻譯成go語言rpc stub代碼的插件protoc-gen-go。
$ goctl env check -i -f --verbose
[goctl-env]: preparing to check env
[goctl-env]: looking up "protoc"
[goctl-env]: "protoc" is not found in PATH
[goctl-env]: preparing to install "protoc"
"protoc" installed from cache
[goctl-env]: "protoc" is already installed in "/Users/keson/go/bin/protoc"
[goctl-env]: looking up "protoc-gen-go"
[goctl-env]: "protoc-gen-go" is not found in PATH
[goctl-env]: preparing to install "protoc-gen-go"
"protoc-gen-go" installed from cache
[goctl-env]: "protoc-gen-go" is already installed in "/Users/keson/go/bin/protoc-gen-go"
[goctl-env]: looking up "protoc-gen-go-grpc"
[goctl-env]: "protoc-gen-go-grpc" is not found in PATH
[goctl-env]: preparing to install "protoc-gen-go-grpc"
"protoc-gen-go-grpc" installed from cache
[goctl-env]: "protoc-gen-go-grpc" is already installed in "/Users/keson/go/bin/protoc-gen-go-grpc"
[goctl-env]: congratulations! your goctl environment is ready!
protoc-x.x.x-osx-x86_64.zip
?并進(jìn)入?protoc-x.x.x-osx-x86_64
? $ cd protoc-x.x.x-osx-x86_64/bin
$ mv protoc $GOPATH/bin
Tip
$GOPATH為你本機(jī)的實(shí)際文件夾地址
$ protoc --version
libprotoc x.x.x
$ go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
$ go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
更多建議: