Skip to content

Commit

Permalink
doc: sync generating multiple handlers for multiple services (#1136)
Browse files Browse the repository at this point in the history
Co-authored-by: yuxuan.wang1 <[email protected]>
  • Loading branch information
alice-yyds and DMwangnima authored Sep 13, 2024
1 parent 08c3ff2 commit 58281c1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,26 @@ description: "Kitex supports generating handlers for each service in multiple se
---

> Support Version: Kitex Tool >= v0.11.0
## Function Description

Starting from v0.8.0, Kitex supports defining multiple services in one idl (both thrift and protobuf are supported). For details, please refer to [Multiple Services](/docs/kitex/tutorials/advanced-feature/multi_service/multi_service). However, in the generated code, the handler.go corresponding to multiple services will be overwritten, and only the handler corresponding to the last service in the idl will be retained.
Starting from v0.8.0, Kitex supports defining multiple services in one idl (both thrift and protobuf are supported). For details, please refer to [Multiple Services](/docs/kitex/tutorials/advanced-feature/multi_service/multi_service/). However, in the generated code, the handler.go corresponding to multiple services will be overwritten, and only the handler corresponding to the last service in the idl will be retained.

Since v0.11.0, Kitex Tool supports generating handlers for each service and registering them uniformly to the server.

## Usage Approach

### Install

Install Kitex Tool with version >= v0.11.0:

```
go install github.com/cloudwego/kitex/tool/cmd/[email protected]
```
- configure `-tpl multiple_services`

### configure -tpl multiple_services
Kitex Tool >= v0.11.0

```bash
kitex -tpl multiple_services -service your_service path/to/idl
```

## Generation Result
## 3. Generation Result

### thrift idl
### 3.1 thrift idl

Take the following thrift idl as an example:

Expand Down Expand Up @@ -100,7 +95,7 @@ func main() {
}
```

### pb idl
### 3.2 pb idl

Take the following pb idl as an example:

Expand Down Expand Up @@ -146,4 +141,4 @@ service C {
}
```

The code generation structure and the content of main.go are consistent with thrift idl.
The code generation structure and the content of main.go are consistent with thrift idl.
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,26 @@ description: "Kitex 支持在多 Service 场景为每个 Service 生成 Handler
---

> 支持版本:Kitex Tool >= v0.11.0
## 功能说明

Kitex 从 v0.8.0 开始支持在一个 idl (同时支持 thrift 和 protobuf) 中定义多个 Service,详情请参考[单 Server 多 Service](/zh/docs/kitex/tutorials/advanced-feature/multi_service/multi_service)。但是生成代码中多个 Service 对应的 handler.go 会被覆盖,只保留 idl 中最后一个 Service 对应的 Handler。
从 v0.11.0 开始,Kitex Tool 支持为每个 Service 生成 Handler 并统一注册到 Server。
## 功能说明

## 使用
Kitex 从 v0.8.0 开始支持在一个 idl (同时支持 thrift 和 protobuf) 中定义多个 service,详情请参考[单 Server 多 Service](/zh/docs/kitex/tutorials/advanced-feature/multi_service/multi_service/)。但是生成代码中多个 service 对应的 handler.go 会被覆盖,只保留 idl 中最后一个 service 对应的 handler。

### 安装
从 v0.11.0 开始,Kitex Tool 支持为每个 service 生成 handler 并统一注册到 server。

安装版本 >= v0.11.0 的 Kitex Tool:
## 使用说明

```
go install github.com/cloudwego/kitex/tool/cmd/[email protected]
```
- 需指定 -tpl multiple_services

### 指定 -tpl multiple_services
Kitex tool 版本要求 >= v0.11.0

```bash
kitex -tpl multiple_services -service your_service path/to/idl
```

## 生成结果

### thrift idl
### 3.1 thrift idl

以下方 thrift idl 为例:

Expand Down Expand Up @@ -65,9 +60,9 @@ kitex_info.yaml
main.go
```

其中 handler_A.go,handler_B.go,handler_C.go 分别承载 Service A,Service B 以及 Service C 的 Handler
其中 handler_A.go,handler_B.go,handler_C.go 分别承载 Service A,Service B 以及 Service C 的 handler

在 main.go 中,自动注册多 Handler
在 main.go 中,自动注册多 handler

```go
package main
Expand Down Expand Up @@ -100,7 +95,7 @@ func main() {
}
```

### pb idl
### 3.2 pb idl

以下方 pb idl 为例:

Expand Down Expand Up @@ -146,4 +141,4 @@ service C {
}
```

生成代码结构、 main.go 内容与 thrift idl 一致。
生成代码结构和 main.go 内容与 thrift idl 一致。

0 comments on commit 58281c1

Please sign in to comment.