两种方式:
下载地址:https://github.com/google/protobuf/releases
下载地址:https://github.com/gogo/protobuf
1、把bin目录下的protoc.exe及编译插件复制到xxx/bin下,xxxx/bin加入环境变量,当然也可放在其他目录。
2、需加入环境变量,能让系统找到protoc.exe
//指定版本 //注意proto3与proto2的写法有些不同 syntax = "proto3"; //包名,通过protoc生成时go文件时 package test; //请求结构 message ContactBook_Request { int32 lOperationTarget = 1; // 操作目标 int32 lOperationType = 2; // 操作类型 bytes bData = 3; // 数据内容,含二级list或map } //回复结构 message ContactBook_Response { string strCode = 1; //响应 string strMsg = 2; //详细信息 } //接口 service storageInfo { rpc PushStoragedataInfo (ContactBook_Request) returns (ContactBook_Response) {} }
1、在goland里,进入终端-然后进入proto文件所在目录
2、执行命令:
protoc -I ./ --gogo_out=plugins=grpc:. xxxxx.proto