Skip to content

Commit d0a9020

Browse files
committed
change readme to 中文,相信大部分看到此项目的是中文用户
1 parent 172145f commit d0a9020

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

README.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
11

2-
## Installation
2+
## 安装
33

4-
- To use this software, you must install `protoc` compiler: [protobuf](https://github.com/protocolbuffers/protobuf)
4+
- 首先我们需要 `protoc` 编译器: [protobuf](https://github.com/protocolbuffers/protobuf)。一般平台上都有编译好的二进制程序,直接下载加载PATH路径里即可。或者你也可以源代码安装。
55

6-
- Add rpcx plugin into protoc-gen-go:
6+
`protoc`负责将proto文件编译成不同编程语言的代码,一般通过插件的方式实现。
7+
8+
- 编译rpcx插件:
9+
10+
Google提供了go和grpc的`protoc`插件,但是依照官方的解释,不准备将其做成库的方式,所以我们要实现自己的插件的话,需要一点点小技巧。
11+
12+
首先下载`github.com/golang/protobuf`,切换到`v1.3.5`分支。 `v1.4.0`以上的分支是基于protobuf APIV2实现的,目前还在开发之中,所以我们还是采用常用的稳定的版本。
13+
14+
然后把本项目下的`link_rpcx.go`文件和`rpcx`文件夹复制到`protoc-gen-go`文件夹下。
15+
16+
最后我们编译`protoc-gen-go`插件,安装的PATH里的文件夹下。
17+
这个插件除了将proto文件编译成protobuf的Go文件,还包含`grpc`插件和`rpcx`插件。
18+
19+
具体操作步骤可以参考下面的操作:
720

821
```sh
922
export GO111MODULE=off
@@ -22,14 +35,16 @@ go install github.com/golang/protobuf/protoc-gen-go
2235
export PATH=$PATH:$GOPATH/bin
2336
```
2437

25-
Congradulations! Now you can use protoc to compile proto files into rpcx services (use `rpcx` plugin):
38+
如果你到达了这一步,恭喜你,包含rpcx插件的protoc-gen-go你就编译安装成功了,按照下面的命令你就可以将proto中定义的service编译成rpcx的服务和客户端代码了:
2639
```sh
2740
protoc -I.:${GOPATH}/src --go_out=plugins=rpcx:. *.proto
2841
```
2942

30-
# Example
43+
# 例子
44+
45+
- proto文件
3146

32-
- Proto file
47+
最简单的一个打招呼的rpc服务。
3348

3449
```proto
3550
syntax = "proto3";
@@ -55,18 +70,19 @@ message HelloReply {
5570
}
5671
```
5772

58-
- Generate the code
73+
- 使用protoc编译器编译出Go代码
5974

6075
```sh
6176
protoc --go_out=plugins=rpcx:. helloworld.proto
6277
```
6378

64-
It will generate `helloworld.pb.go` file, which includes code of Request、Response、Server skeleton and Client stub.
79+
上述命令生成了 `helloworld.pb.go` 文件, 它包含各种struct的定义, 还有服务端的一个骨架, 以及客户端的代码。
80+
81+
- 服务端代码
6582

66-
- Server
83+
服务端的代码只是一个骨架,很显然你要实现你的逻辑。比如这个打招呼的例子, 客户端传入一个名称,你可以返回一个`hello <name>`的字符串。
6784

68-
The generated code provides a server skeleton. You can implement business logics based on this skeleton.
69-
Business logics of the below code are very simple, just a popluar `hello world` program.
85+
它还提供了一个简单启动服务的方法,你可以在此基础上实现服务端的代码,注册很多的服务,配置注册中心和其它插件等等。
7086

7187
```go
7288
package main
@@ -99,9 +115,12 @@ func (s *GreeterImpl) SayHello(ctx context.Context, args *helloworld.HelloReques
99115
}
100116
```
101117

102-
- Client
118+
- 客户端代码
119+
120+
客户端生成的代码更友好,它包装了`XClient`对象,提供了符合人工美学的方法调用格式(请求参数作为方法参数,返回结果作为方法的返回值)。并且提供了客户端的配置方式。
121+
122+
你也可以扩展客户端的配置,提供注册中心、路由算法,失败模式、重试、熔断等服务治理的设置。 
103123

104-
The generated client uses simple configuration to access `Greeter` service.
105124

106125
```go
107126
package main

0 commit comments

Comments
 (0)