参考资料
Mac 安装 protoc 指定版本
https://www.jianshu.com/p/580fb02f3929
https://www.cnblogs.com/china-golang/p/16142396.html
安装protoc
运行如下命令
go install github.com/golang/protobuf/protoc-gen-go@latest
1,出现异常protoc-gen-go-grpc: program not found or is not executable,需要安装以下命令
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
2,出现异常protoc-gen-validate: program not found or is not executable Please specify a program using absolute path or make sure the program is available in your PATH system variable --validate_out: protoc-gen-validate: Plugin failed with status code 1.,需要安装以下命令
//第一步
git clone https://github.com/envoyproxy/protoc-gen-validate
//第二步
cd 你拉取的protoc-gen-validate项目的文件路径
//第三步
go install .
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;
}
protoc --go_out=plugins=grpc:./ ./hello.proto