Skip to content

Commit 1c992ba

Browse files
authored
docs: fix typos and update streamx documentation (#1506)
Signed-off-by: rogerogers <rogers@rogerogers.com>
1 parent 8788f90 commit 1c992ba

15 files changed

Lines changed: 90 additions & 39 deletions

content/en/docs/kitex/Tutorials/basic-feature/streamx/StreamX_Basic_Programming.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The protocol selected here only affects code generated from IDL. Regardless of t
3131

3232
File `echo.thrift `:
3333

34-
```go
34+
```thrift
3535
namespace go echo
3636
3737
service TestService {
@@ -65,8 +65,10 @@ import "github.com/cloudwego/kitex/client"
6565

6666
cli, err := testservice.NewClient(
6767
"a.b.c",
68-
client.WithStreamRecvMiddleware(...),
69-
client.WithStreamSendMiddleware(...),
68+
client.WithStreamOptions(
69+
client.WithStreamRecvMiddleware(...),
70+
client.WithStreamSendMiddleware(...),
71+
),
7072
)
7173
```
7274

@@ -78,8 +80,10 @@ import "github.com/cloudwego/kitex/server"
7880

7981
svr := testservice.NewServer(
8082
new(serviceImpl),
81-
server.WithStreamRecvMiddleware(...),
82-
server.WithStreamSendMiddleware(...),
83+
server.WithStreamOptions(
84+
server.WithStreamRecvMiddleware(...),
85+
server.WithStreamSendMiddleware(...),
86+
),
8387
)
8488
```
8589

content/en/docs/kitex/Tutorials/basic-feature/streamx/StreamX_Error_Handling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Usage example: For example, in the ChatGPT scenario, we need to constantly check
5656
```go
5757
func (si *streamingService) ServerStreamWithErr(ctx context.Context, req *echo.Request, stream echo.TestService_ServerStreamWithErrServer) error {
5858
// Check user account balance
59-
for isHasBalance (req.UserId) {
59+
for hasBalance(req.UserId) {
6060
stream.Send(ctx, res)
6161
}
6262
// Return insufficient user balance error

content/en/docs/kitex/Tutorials/basic-feature/streamx/StreamX_FAQ.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ Note that since the check depends on the GC timing, the delay monitoring of the
1616

1717
### Client persistent stream object causes stream leak
1818

19-
If the user holds the stream object for a long time and does not actively call stream. CloseSend, the framework will naturally assume that the stream still needs to be used, and will not close the stream and related gorotuines.
19+
If the user holds the stream object for a long time and does not actively call stream.CloseSend(), the framework will naturally assume that the stream still needs to be used, and will not close the stream and related goroutines.
2020

2121
### Server call Recv stuck
2222

23-
If the client keeps a stream active and does not call CloseSend, the stream. Recv () function will not return.
23+
If the client keeps a stream active and does not call CloseSend, the stream.Recv() function will not return.
2424

2525
If the server wants to avoid problems caused by incorrect usage of client users, it can customize its own timeout logic in the ctx of Recv (ctx). For example:
2626

content/en/docs/kitex/Tutorials/basic-feature/streamx/StreamX_Metainfo.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Reverse pass-through introduces a new concept, Header and Trailer. Any complete
4242
Use these two frames to reverse pass-through information.
4343

4444
```go
45-
import "github.com/cloudwego/pkg/streaming"
45+
import "github.com/cloudwego/kitex/pkg/streaming"
4646

4747
func (s *streamingService) EchoClient(ctx context.Context,
4848
stream echo.TestService_EchoClientServer) (err error) {
@@ -55,7 +55,7 @@ func (s *streamingService) EchoClient(ctx context.Context,
5555
return err
5656
}
5757
// send normal data
58-
err = stream.Send(req)
58+
err = stream.Send(ctx, resp)
5959
}
6060
```
6161

content/en/docs/kitex/Tutorials/basic-feature/streamx/StreamX_Middleware.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type UnaryMiddleware func(next UnaryEndpoint) UnaryEndpoint
7676
### Inject client-side middlewares
7777

7878
```go
79-
import "github.com/cloudwego/client"
79+
import "github.com/cloudwego/kitex/client"
8080

8181
cli, err := xxx.NewClient(
8282
"a.b.c",
@@ -109,7 +109,7 @@ cli, err := xxx.NewClient(
109109
### Inject server-side middlewares
110110

111111
```go
112-
import "github.com/cloudwego/server"
112+
import "github.com/cloudwego/kitex/server"
113113

114114
svr, err := xxx.NewServer(
115115
//...

content/en/docs/kitex/Tutorials/options/client_options.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ func WithMiddlewareBuilder(mwb endpoint.MiddlewareBuilder) Option
9191

9292
Add middleware depends on the context passed in by the framework that contains runtime configuration information (the context of non-RPC calls), so that the middleware can take advantage of the framework's information when initializing.
9393

94+
### WithStreamOptions
95+
96+
```go
97+
func WithStreamOptions(opts ...client.StreamOption) Option
98+
```
99+
100+
**Kitex >= v0.13.0 adds this option.**
101+
102+
Aggregate streaming-related options such as StreamMiddleware, StreamSendMiddleware, StreamRecvMiddleware, RecvTimeout. Works for streaming methods.
103+
See [StreamX Middleware](../../basic-feature/streamx/streamx_middleware/).
104+
94105
### WithCircuitBreaker
95106

96107
```go

content/en/docs/kitex/Tutorials/options/server_options.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ func WithMiddlewareBuilder(mwb endpoint.MiddlewareBuilder, funcName ...string) O
6464

6565
Add middleware depends on the context passed in by the framework that contains runtime configuration information (the context of non-RPC calls), so that the middleware can take advantage of the framework's information when initializing.
6666

67+
### WithStreamOptions
68+
69+
```go
70+
func WithStreamOptions(opts ...server.StreamOption) Option
71+
```
72+
73+
**Kitex >= v0.13.0 adds this option.**
74+
75+
Aggregate streaming-related options such as StreamMiddleware, StreamSendMiddleware, StreamRecvMiddleware, RecvTimeout. Works for streaming methods.
76+
See [StreamX Middleware](../../basic-feature/streamx/streamx_middleware/).
77+
6778
### WithLimit
6879

6980
```go

content/zh/docs/kitex/Tutorials/basic-feature/streamx/StreamX_Basic_Programming.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ description: ""
3131

3232
文件 `echo.thrift`:
3333

34-
```go
34+
```thrift
3535
namespace go echo
3636
3737
service TestService {
@@ -60,14 +60,16 @@ kitex -streamx -module <go module> -service service echo.thrift
6060
#### 创建 Client
6161

6262
```go
63-
// 生成代码目录,streamserver 为 IDL 定义的 service name
63+
// 生成代码目录,testservice 为 IDL 定义的 service name
6464
import ".../kitex_gen/echo/testservice"
6565
import "github.com/cloudwego/kitex/client"
6666

6767
cli, err := testservice.NewClient(
6868
"a.b.c",
69-
client.WithStreamRecvMiddleware(...),
70-
client.WithStreamSendMiddleware(...),
69+
client.WithStreamOptions(
70+
client.WithStreamRecvMiddleware(...),
71+
client.WithStreamSendMiddleware(...),
72+
),
7173
)
7274
```
7375

@@ -79,8 +81,10 @@ import "github.com/cloudwego/kitex/server"
7981

8082
svr := testservice.NewServer(
8183
new(serviceImpl),
82-
streamxserver.WithStreamRecvMiddleware(...),
83-
streamxserver.WithStreamSendMiddleware(...),
84+
server.WithStreamOptions(
85+
server.WithStreamRecvMiddleware(...),
86+
server.WithStreamSendMiddleware(...),
87+
),
8488
)
8589
```
8690

@@ -111,9 +115,9 @@ client.CloseAndRecv(res) === EOF ==> server.Recv(EOF)
111115
```go
112116
stream, err := cli.EchoClient(ctx)
113117
for i := 0; i < 3; i++ {
114-
err = cs.Send(stream.Context(), req)
118+
err = stream.Send(stream.Context(), req)
115119
}
116-
res, err = cs.CloseAndRecv(stream.Context())
120+
res, err = stream.CloseAndRecv(stream.Context())
117121
```
118122

119123
#### Server 用法
@@ -220,7 +224,7 @@ go func() {
220224
for i := 0; i < round; i++ {
221225
err := stream.Send(stream.Context(), req)
222226
}
223-
err = bs.CloseSend(stream.Context())
227+
err = stream.CloseSend(stream.Context())
224228
}()
225229
go func() {
226230
defer wg.Done()

content/zh/docs/kitex/Tutorials/basic-feature/streamx/StreamX_Error_Handling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ TTHeader Streaming 错误汇总
5656
```go
5757
func (si *streamingService) ServerStreamWithErr(ctx context.Context, req *echo.Request, stream echo.TestService_ServerStreamWithErrServer) error {
5858
// 检查用户账户余额
59-
for isHasBalance (req.UserId) {
59+
for hasBalance(req.UserId) {
6060
stream.Send(ctx, res)
6161
}
6262
// 返回用户余额不足错误

content/zh/docs/kitex/Tutorials/basic-feature/streamx/StreamX_FAQ.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ kitex 会在检查用户不再持有 stream 对象时,主动调用一次 Close
1616

1717
### Client 持久化 stream 导致 stream 泄漏
1818

19-
如果用户长期持有 stream 对象,而且不主动调用 stream.CloseSend ,框架会理所应当认为该 stream 还需要被使用,进而不会关闭 stream 以及相关 gorotuine
19+
如果用户长期持有 stream 对象,而且不主动调用 stream.CloseSend(),框架会认为该 stream 仍需使用,进而不会关闭 stream 以及相关 goroutine
2020

2121
### Server 调用 Recv 卡死
2222

0 commit comments

Comments
 (0)