先安装好工具
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
下载安装protoc
wget https://github.com/protocolbuffers/protobuf/releases/download/v25.0/protoc-25.0-linux-x86_64.zip
# 解压后将protoc二进制文件设置到环境变量里面
测试
proto代码
syntax = "proto3";
option go_package = "../proto";
message HelloRequest {
string name = 1; //
int32 age = 2;
}
生成
protoc --go_out=. --go-grpc_out=. helloword.proto
标签:protoc,protobuf,示例,grpc,proto,go,Go
From: https://www.cnblogs.com/postkarte/p/17810933.html