golang rpc
小于 1 分钟
grpc:https://grpc.io/docs/languages/go/quickstart/
安装proto
下载地址:https://github.com/protocolbuffers/protobuf/releases
下载解压
wget https://github.com/protocolbuffers/protobuf/releases/download/v26.1/protoc-26.1-linux-x86_64.zip
unzip protoc-26.1-linux-x86_64.zip
我们把protoc
放在/usr/local/bin
可执行程序目录中,这样全局都可以访问到,同时把include
目录的内容也复制到/usr/local/include/
中
sudo mv bin/protoc /usr/local/bin
sudo mv include/google /usr/local/include
# 查看是否安装成功
protoc --version # libprotoc 25.3
# 安装插件
sudo go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
sudo go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
go get -u google.golang.org/protobuf/cmd/protoc-gen-go
sudo go install google.golang.org/protobuf/cmd/protoc-gen-go
go get -u google.golang.org/grpc/cmd/protoc-gen-go-grpc
sudo go install google.golang.org/grpc/cmd/protoc-gen-go-grpc
# 检查protoc-gen-go 是否安装成功
protoc-gen-go --version
编译proto
app.proto
syntax = "proto3";
option go_package = "./app";
package app;
message Person {
int32 age = 1;
string name = 2;
}
message User{
Person person = 3;
int32 weight = 180;
}
protoc --go_out=./ *proto
grpc
protoc --go_grpc_out=. *.proto