golang grpc通过proto生成文件
首先需要安装protoc
https://grpc.io/docs/protoc-installation/

1、编写invoicer.proto文件
syntax = "proto3";
option go_package = "github.com/he-mike/demo-grpc/invoicer";
message Amount {
int64 amount = 1;
string currency = 2;
}
message CreateRequest {
Amount amount = 1;
string from = 2;
string to = 3;
}
message CreateResponse {
bytes pdf = 1;
bytes docx = 2;
}
//grpc生成
service Invoicer {
rpc Create(CreateRequest) returns (CreateResponse);
}
2、运行文件invoicer.proto中invoicer目录生成文件
protoc
--go_out=invoicer
--go_opt=paths=source_relative
--go-grpc_out=invoicer
--go-grpc_opt=paths=source_relative
invoicer.proto
指定输出目录invoicer
使用Makefile文件(同级目录下输入)
make generate_grpc_code

浙公网安备 33010602011771号