1. 下载安装 protoc 并将 protoc.exe 设置为全局环境变量
https://github.com/google/protobuf/releaseshttps://github.com/google/protobuf/releases2. cmd 查看是否安装成功 ,本机安装为 libprotoc 3.19.1
protoc --version
--------------------------------------------------------------------------------------------------------------------------------
3. 编写 hello.proto 文件测试
syntax = "proto3";
package hello;
// 定义 go语言的包存放地址
option go_package="hello/hello";
// 定义扩展名
service Hello {
rpc Run(Requests) returns(Responses) {}
}
message Requests {
string name = 1;
}
message Responses {
string message = 2;
}
4. 生成代码测试 命令
1. 生成代码命令
protoc --go_out=plugins=grpc:./helloGo ./hello.proto
2. 此时当前目录会变为
demo2\helloGo\hello\hello\hello.pb.go
demo2\hello.proto
5. success