Skip to content

Commit 99cc80d

Browse files
authored
Merge pull request #10 from win5do/master
fix: article layout problem
2 parents 08c5c27 + bce6df4 commit 99cc80d

File tree

10 files changed

+83
-72
lines changed

10 files changed

+83
-72
lines changed

Diff for: .gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ _book
1313
# eBook build output
1414
*.epub
1515
*.mobi
16-
*.pdf
16+
*.pdf
17+
18+
.idea

Diff for: part1/function.md

+17-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ Rpcx 也支持将纯函数注册为服务,函数必须满足以下的要求:
2020

2121
服务端必须使用 `RegisterFunction` 来注册一个函数并且提供一个服务名。
2222

23-
```go server.go
23+
```go
24+
// server.go
2425
type Args struct {
2526
A int
2627
B int
@@ -46,21 +47,22 @@ func main() {
4647

4748
客户端可以通过服务名和函数名来调用服务:
4849

49-
```go client.go
50-
d := client.NewPeer2PeerDiscovery("tcp@"+*addr, "")
51-
xclient := client.NewXClient("a.fake.service", client.Failtry, client.RandomSelect, d, client.DefaultOption)
52-
defer xclient.Close()
50+
```go
51+
// client.go
52+
d := client.NewPeer2PeerDiscovery("tcp@"+*addr, "")
53+
xclient := client.NewXClient("a.fake.service", client.Failtry, client.RandomSelect, d, client.DefaultOption)
54+
defer xclient.Close()
5355

54-
args := &example.Args{
55-
A: 10,
56-
B: 20,
57-
}
56+
args := &example.Args{
57+
A: 10,
58+
B: 20,
59+
}
5860

59-
reply := &example.Reply{}
60-
err := xclient.Call(context.Background(), "mul", args, reply)
61-
if err != nil {
62-
log.Fatalf("failed to call: %v", err)
63-
}
61+
reply := &example.Reply{}
62+
err := xclient.Call(context.Background(), "mul", args, reply)
63+
if err != nil {
64+
log.Fatalf("failed to call: %v", err)
65+
}
6466

65-
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
67+
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
6668
```

Diff for: part1/transport.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ rpcx 可以通过 TCP、HTTP、UnixDomain、QUIC和KCP通信。你也可以使
99
**Example:** [101basic](https://github.com/rpcx-ecosystem/rpcx-examples3/tree/master/101basic)
1010

1111
服务端使用 `tcp` 做为网络名并且在注册中心注册了名为 `serviceName/tcp@ipaddress:port` 的服务。
12-
```go server.go
12+
```go
1313
s.Serve("tcp", *addr)
1414
```
1515

Diff for: part2/registry.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ Consul也是使用Go开发的,在Go生态圈也被广泛应用。
230230

231231
* ServiceAddress: 本机的监听地址, 这个对外暴露的监听地址, 格式为`tcp@ipaddress:port`
232232
* ConsulServers: consul集群的地址
233-
* BasePath: 服务前缀。 如果有多个项目同时使用zookeeper,避免命名冲突,可以设置这个参数,为当前的服务设置命名空间
233+
* BasePath: 服务前缀。 如果有多个项目同时使用consul,避免命名冲突,可以设置这个参数,为当前的服务设置命名空间
234234
* Metrics: 用来更新服务的TPS
235235
* UpdateInterval: 服务的刷新间隔, 如果在一定间隔内(当前设为2 * UpdateInterval)没有刷新,服务就会从consul中删除
236236

Diff for: part3/group.md

+24-22
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
`group` 就是一个元数据。如果你为服务设置了设置`group`, 只有在这个`group`的客户端才能访问这些服务(这个限制是在路由的时候限制的, 当然你在客户端绕过这个限制)。
1111

1212

13-
```go server.go
13+
```go
14+
// server.go
1415

1516
func main() {
1617
flag.Parse()
@@ -38,25 +39,26 @@ func createServer2(addr, meta string) {
3839

3940
如果在客户端你没有设置 `option.Group`, 客户端可以访问这些服务, 无论服务是否设置了组还是没设置。
4041

41-
```go client.go
42-
option := client.DefaultOption
43-
option.Group = "test"
44-
xclient := client.NewXClient("Arith", client.Failover, client.RoundRobin, d, option)
45-
defer xclient.Close()
46-
47-
args := &example.Args{
48-
A: 10,
49-
B: 20,
50-
}
51-
52-
for {
53-
reply := &example.Reply{}
54-
err := xclient.Call(context.Background(), "Mul", args, reply)
55-
if err != nil {
56-
log.Fatalf("failed to call: %v", err)
57-
}
58-
59-
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
60-
time.Sleep(1e9)
61-
}
42+
```go
43+
// client.go
44+
option := client.DefaultOption
45+
option.Group = "test"
46+
xclient := client.NewXClient("Arith", client.Failover, client.RoundRobin, d, option)
47+
defer xclient.Close()
48+
49+
args := &example.Args{
50+
A: 10,
51+
B: 20,
52+
}
53+
54+
for {
55+
reply := &example.Reply{}
56+
err := xclient.Call(context.Background(), "Mul", args, reply)
57+
if err != nil {
58+
log.Fatalf("failed to call: %v", err)
59+
}
60+
61+
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
62+
time.Sleep(1e9)
63+
}
6264
```

Diff for: part3/heartbeat.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ rpcx会自动处理心跳(事实上它直接就丢弃了心跳)。
88
客户端需要启用心跳选项,并且设置心跳间隔:
99

1010
```go
11-
option := client.DefaultOption
12-
option.Heartbeat = true
13-
option.HeartbeatInterval = time.Second
11+
option := client.DefaultOption
12+
option.Heartbeat = true
13+
option.HeartbeatInterval = time.Second
1414
```

Diff for: part3/metadata.md

+10-8
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515

1616
如果你想在客户端读取客户端的数据, 你 **必须** 在上下文中设置 `share.ResMetaDataKey`
1717

18-
```go client.go
19-
reply := &example.Reply{}
20-
ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{"aaa": "from client"})
21-
ctx = context.WithValue(ctx, share.ResMetaDataKey, make(map[string]string))
22-
err := xclient.Call(ctx, "Mul", args, reply)
18+
```go
19+
// client.go
20+
reply := &example.Reply{}
21+
ctx := context.WithValue(context.Background(), share.ReqMetaDataKey, map[string]string{"aaa": "from client"})
22+
ctx = context.WithValue(ctx, share.ResMetaDataKey, make(map[string]string))
23+
err := xclient.Call(ctx, "Mul", args, reply)
2324
```
2425

2526
## Server
2627

2728
服务器可以从上下文读取`share.ReqMetaDataKey``share.ResMetaDataKey`:
2829

29-
```go server.go
30-
reqMeta := ctx.Value(share.ReqMetaDataKey).(map[string]string)
31-
resMeta := ctx.Value(share.ResMetaDataKey).(map[string]string)
30+
```go
31+
// server.go
32+
reqMeta := ctx.Value(share.ReqMetaDataKey).(map[string]string)
33+
resMeta := ctx.Value(share.ResMetaDataKey).(map[string]string)
3234
```

Diff for: part3/state.md

+19-18
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
你可以通过 [rpcx-ui](https://github.com/smallnest/rpcx-ui))来时实现禁用和启用的功能。
1010

11-
```go server.go
12-
11+
```go
12+
// server.go
1313
func main() {
1414
flag.Parse()
1515

@@ -33,23 +33,24 @@ func createServer2(addr, meta string) {
3333
```
3434

3535

36-
```go client.go
37-
xclient := client.NewXClient("Arith", client.Failover, client.RoundRobin, d, client.DefaultOption)
38-
defer xclient.Close()
36+
```go
37+
// client.go
38+
xclient := client.NewXClient("Arith", client.Failover, client.RoundRobin, d, client.DefaultOption)
39+
defer xclient.Close()
3940

40-
args := &example.Args{
41-
A: 10,
42-
B: 20,
43-
}
41+
args := &example.Args{
42+
A: 10,
43+
B: 20,
44+
}
4445

45-
for {
46-
reply := &example.Reply{}
47-
err := xclient.Call(context.Background(), "Mul", args, reply)
48-
if err != nil {
49-
log.Fatalf("failed to call: %v", err)
50-
}
46+
for {
47+
reply := &example.Reply{}
48+
err := xclient.Call(context.Background(), "Mul", args, reply)
49+
if err != nil {
50+
log.Fatalf("failed to call: %v", err)
51+
}
5152

52-
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
53-
time.Sleep(1e9)
54-
}
53+
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
54+
time.Sleep(1e9)
55+
}
5556
```

Diff for: part3/timeout.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
你可以使用`OptionFn`设置服务器的 `readTimeout``writeTimeout`
1010

11-
```go server struct
11+
```go
1212
type Server struct {
1313
……
1414
readTimeout time.Duration

Diff for: part6/bidirectional.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ func (s *Server) SendMessage(conn net.Conn, servicePath, serviceMethod string, m
2222
```
2323

2424

25-
```go server.go
25+
```go
26+
// server.go
2627
func main() {
2728
flag.Parse()
2829

@@ -56,7 +57,8 @@ func main() {
5657

5758
你必须使用 `NewBidirectionalXClient` 创建 XClient 客户端, 你需要传如一个channel, 这样你就可以从channel中读取通知了。
5859

59-
```go client.go
60+
```go
61+
// client.go
6062
func main() {
6163
flag.Parse()
6264

0 commit comments

Comments
 (0)