Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cwgo):a built-in template description #1090

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion content/en/docs/cwgo/tutorials/templete-extension/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ linkTitle: "Template Extension"
weight: 1
description: >
---

The cwgo tool also supports passing its own template, and the template syntax is the syntax of go template. cwgo also welcomes users to contribute their own templates. Due to the different concepts of RPC and HTTP, the corresponding template variables also have some differences, please refer to the following for details.

To pass a custom template, add the `-template` parameter to the command, such as:
Expand Down Expand Up @@ -71,6 +70,33 @@ Best practice rpc example tpl can refer to [here](https://github.com/cloudwego/c

Best practice http example tpl can refer to [here](https://github.com/cloudwego/cwgo/tree/main/tpl/hertz/standard).

## standard_v2
The cwgo tool has a built-in template, the main changes of which are as follows:

### The Api call returns the corresponding response code

```
func CreateApp(){
...
err = c.BindAndValidate(&req)
if err !=nil{
utils.SendErrResponse(ctx, c, consts.StatusBadRequest, err)
return
}
...
}
```

### Server subcontract generation
Now `biz/service` will be treated in the same way as `biz/handler`, generated by package.
![img](/img/docs/cwgo_templete-extension_standard-v2.png)

### How to use
```sh
cwgo server --type http --idl idl/hello.thrift --server_name hellotest --module cwgo_test --template standard_v2
```
Specify the template as `standard_ v2`

## Appendix

### Kitex PackageInfo structure meaning
Expand Down Expand Up @@ -127,3 +153,4 @@ type MethodInfo struct {
Server Streaming bool
}
```

28 changes: 27 additions & 1 deletion content/zh/docs/cwgo/tutorials/templete-extension/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ linkTitle: "模板拓展"
weight: 1
description: >
---

cwgo 工具也支持传递自己的模板,模版语法为 go template 的语法。cwgo 也欢迎用户贡献自己的模板。由于 RPC 和 HTTP 概念不同,其对应的模版变量也有一些差异,详细请参考下文。

如需传递自定义模板,请给命令添加 `-template` 参数,如:
Expand Down Expand Up @@ -71,6 +70,33 @@ cwgo server -type RPC -service {service name} -idl {idl path} -template git@git

最佳实践的 http 示例 tpl 可参考[这里](https://github.com/cloudwego/cwgo/tree/main/tpl/hertz/standard)。

## standard_v2
cwgo 工具内置了一个模板,该模板主要改动如下:

### Api 调用返回对应的响应码。

```
func CreateApp(){
...
err = c.BindAndValidate(&req)
if err !=nil{
utils.SendErrResponse(ctx, c, consts.StatusBadRequest, err)
return
}
...
}
```

### server 分包生成
现在 `biz/service` 会和 `biz/handler` 一样处理,按包生成。
![img](/img/docs/cwgo_templete-extension_standard-v2.png)

### 如何使用
```sh
cwgo server --type http --idl idl/hello.thrift --server_name hellotest --module cwgo_test --template standard_v2
```
指定模板为 `standard_v2`

## 附录

### Kitex PackageInfo 结构体含义
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading