Skip to content

Commit bce6df4

Browse files
author
wufeng
committed
fix: article layout problem
1 parent 0089e34 commit bce6df4

File tree

5 files changed

+57
-52
lines changed

5 files changed

+57
-52
lines changed

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

0 commit comments

Comments
 (0)