From d24f770a971f59f287195c69de0b979983070549 Mon Sep 17 00:00:00 2001 From: erichuowen Date: Thu, 4 Jun 2020 19:46:05 +0800 Subject: [PATCH] =?UTF-8?q?+protoc=E7=94=9F=E6=88=90=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-CN.md | 42 ++++++++++++++++++++++++++++++++++++++++++ README.md | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/README-CN.md b/README-CN.md index 5411571..6edf79a 100644 --- a/README-CN.md +++ b/README-CN.md @@ -100,6 +100,48 @@ func main() { 更多细节可以参考 [helloworld](https://github.com/lubanproj/gorpc/tree/master/examples/helloworld) +See [helloworld](https://github.com/lubanproj/gorpc/tree/master/examples/helloworld) for more details + +或者以代码生成方式调用全过程 + +1. 定义一个服务,这里用proto文件的形式进行定义 +2. 安装protoc-gen-gorpc代码生成工具,在终端执行(前提是需要已经安装protoc工具,详情可参考protoc-gen-go安装) +3. 执行 + +**1. 定义一个服务,这里用proto文件的形式进行定义** + +``` +synax = "proto3"; + +package helloworld; + +service Greeter { + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +message HelloRequest { + string msg = 1; +} + +message HelloReply { + string msg = 1; +} + +``` + +**2. 安装protoc-gen-gorpc代码生成工具** + +``` +go get github.com/lubanproj/protoc-gen-gorpc +``` + +**3. 执行** + +``` +protoc --gorpc_out=plugin:. helloworld.proto +``` + +更多细节可以参考 [helloworld2](https://github.com/lubanproj/gorpc/tree/master/examples/helloworld2) ### 文档 diff --git a/README.md b/README.md index d9d9f83..b5333e5 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,47 @@ func main() { See [helloworld](https://github.com/lubanproj/gorpc/tree/master/examples/helloworld) for more details +Or you only need three steps to complete a service call by code generation + +1. define a service by .proto file +2. install protoc-gen-gorpc for code generation +3. execute protoc + +**1. define a service by .proto file** + +``` +synax = "proto3"; + +package helloworld; + +service Greeter { + rpc SayHello (HelloRequest) returns (HelloReply) {} +} + +message HelloRequest { + string msg = 1; +} + +message HelloReply { + string msg = 1; +} + +``` + +**2. install protoc-gen-gorpc for code generation** + +``` +go get github.com/lubanproj/protoc-gen-gorpc +``` + +**3. execute protoc** + +``` +protoc --gorpc_out=plugin:. helloworld.proto +``` + +See [helloworld2](https://github.com/lubanproj/gorpc/tree/master/examples/helloworld2) for more details + ### Documentation - [Examples](https://github.com/lubanproj/gorpc/tree/master/examples).