1.去网站下载 protoc对应的文件
https://github.com/protocolbu...
下载解压之后,protoc.exe 放到 go 对应的bin 目录下.
2.从github上下载我的项目到本地,而后编译
git clone https://github.com/golang/pro...
go build
生成的protoc-gen-go.exe文件也Copy 到go 对应的bin 目录下.
3.如何应用
定义 hello.proto 文件:
syntax = "proto3"; // 指定proto版本package hello;// protoc -I . --go_out=plugins=grpc:. ./hello.proto//定义包名称option go_package = "hello";// 定义Hello服务service Hello{ // 定义SayHello办法 rpc SayHello(HelloRequest) returns (HelloResponse){}}// HelloRequest 申请构造message HelloRequest{ string name = 1;}// HelloResponse 响应构造message HelloResponse{ string message = 1;}
在命令行cd 到该目录,执行命令protoc --go_out=. hello.proto
生成了hello.pb.go文件