diff --git a/content/en/docs/cwgo/tutorials/templete-extension/_index.md b/content/en/docs/cwgo/tutorials/templete-extension/_index.md index 58f7c35059c..3ac7c12d90c 100644 --- a/content/en/docs/cwgo/tutorials/templete-extension/_index.md +++ b/content/en/docs/cwgo/tutorials/templete-extension/_index.md @@ -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: @@ -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 @@ -127,3 +153,4 @@ type MethodInfo struct { Server Streaming bool } ``` + diff --git a/content/zh/docs/cwgo/tutorials/templete-extension/_index.md b/content/zh/docs/cwgo/tutorials/templete-extension/_index.md index 34a3f856ab6..82a14f32dd0 100644 --- a/content/zh/docs/cwgo/tutorials/templete-extension/_index.md +++ b/content/zh/docs/cwgo/tutorials/templete-extension/_index.md @@ -4,7 +4,6 @@ linkTitle: "模板拓展" weight: 1 description: > --- - cwgo 工具也支持传递自己的模板,模版语法为 go template 的语法。cwgo 也欢迎用户贡献自己的模板。由于 RPC 和 HTTP 概念不同,其对应的模版变量也有一些差异,详细请参考下文。 如需传递自定义模板,请给命令添加 `-template` 参数,如: @@ -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 结构体含义 diff --git a/static/img/docs/cwgo_templete-extension_standard-v2.png b/static/img/docs/cwgo_templete-extension_standard-v2.png new file mode 100644 index 00000000000..ff613ecac2f Binary files /dev/null and b/static/img/docs/cwgo_templete-extension_standard-v2.png differ