From 0e5dc1c5ec0834ee8c7346ae7a5841fd9abe7ed0 Mon Sep 17 00:00:00 2001 From: yuxialuozi <3159452953@qq.com> Date: Thu, 30 May 2024 10:55:37 +0800 Subject: [PATCH 1/3] fix:change the parameter service to server_name --- content/en/docs/cwgo/getting-started/_index.md | 2 +- content/en/docs/cwgo/tutorials/client/command.md | 9 +++++++-- content/en/docs/cwgo/tutorials/client/example_pb.md | 4 ++-- .../en/docs/cwgo/tutorials/client/example_thrift.md | 4 ++-- content/en/docs/cwgo/tutorials/server/command.md | 10 +++++++--- content/en/docs/cwgo/tutorials/server/example_pb.md | 4 ++-- .../en/docs/cwgo/tutorials/server/example_thrift.md | 4 ++-- content/zh/docs/cwgo/getting-started/_index.md | 2 +- content/zh/docs/cwgo/tutorials/client/command.md | 10 +++++++--- content/zh/docs/cwgo/tutorials/client/example_pb.md | 4 ++-- .../zh/docs/cwgo/tutorials/client/example_thrift.md | 4 ++-- content/zh/docs/cwgo/tutorials/server/command.md | 9 ++++++--- content/zh/docs/cwgo/tutorials/server/example_pb.md | 4 ++-- .../zh/docs/cwgo/tutorials/server/example_thrift.md | 4 ++-- 14 files changed, 45 insertions(+), 29 deletions(-) diff --git a/content/en/docs/cwgo/getting-started/_index.md b/content/en/docs/cwgo/getting-started/_index.md index af19ea9ec52..3d29ef23fa7 100644 --- a/content/en/docs/cwgo/getting-started/_index.md +++ b/content/en/docs/cwgo/getting-started/_index.md @@ -109,7 +109,7 @@ Let's take thrift as an example: 4. Generate project layout ```shell - cwgo server -service=a.b.c -type HTTP -idl=idl/hello.thrift + cwgo server --server_name a.b.c --type HTTP --idl idl/hello.thrift -module {{your_module_name}} ``` 5. Compile and run diff --git a/content/en/docs/cwgo/tutorials/client/command.md b/content/en/docs/cwgo/tutorials/client/command.md index b30e0ba9e85..6ed6217e569 100644 --- a/content/en/docs/cwgo/tutorials/client/command.md +++ b/content/en/docs/cwgo/tutorials/client/command.md @@ -25,7 +25,8 @@ USAGE: cwgo client [command options] [arguments...] OPTIONS: - --service value Specify the service name. + --service value Specify the server name.(Not recommended) + --server_name value Specify the server name. --type value Specify the generate type. (RPC or HTTP) (default: "RPC") --module value, --mod value Specify the Go module name to generate go.mod. --idl value Specify the IDL file path. (.thrift or .proto) @@ -38,9 +39,13 @@ OPTIONS: --help, -h show help (default: false) ``` +## Attention +- service is not recommended and will be removed from v0.2.0 + ## Specification -- service: Specify the service name for functions such as service registration and discovery +- service: Specify the service name for functions such as service registration and discovery(Not recommended) +- server_name: Specify the service name for functions such as service registration and discovery - type: Specify the generation type, support parameters RPC and HTTP, default to RPC - module/mod: Specify the go mod name, which must be specified outside of GOPATH. In GOPATH, the default name is the path relative to GOPATH - idl: Specify the main IDL file path diff --git a/content/en/docs/cwgo/tutorials/client/example_pb.md b/content/en/docs/cwgo/tutorials/client/example_pb.md index e245cb2bea6..f12b3e357f0 100644 --- a/content/en/docs/cwgo/tutorials/client/example_pb.md +++ b/content/en/docs/cwgo/tutorials/client/example_pb.md @@ -35,7 +35,7 @@ service HelloService { > Note: 项目位于非 GOPATH 下必须指定 gomod,GOPATH 下默认以相对于 GOPATH 的路径作为名字,可不指定 gomod。 ```sh -cwgo client --type RPC --idl hello.proto --service hellotest --module {{your_module_name}} -I . +cwgo client --type RPC --idl hello.proto --server_name hellotest --module {{your_module_name}} -I . ``` ### Generate Code @@ -161,7 +161,7 @@ service HelloService { > Note: If the project is located outside of GOPATH, gomod must be specified. GOPATH defaults to a path relative to GOPATH as the name, and gomod may not be specified. ```sh -cwgo client --type HTTP --idl hello.proto --service hellotest --module {{your_module_name}} +cwgo client --type HTTP --idl hello.proto --server_name hellotest --module {{your_module_name}} ``` ### Generate Code diff --git a/content/en/docs/cwgo/tutorials/client/example_thrift.md b/content/en/docs/cwgo/tutorials/client/example_thrift.md index 22f3089a6a5..e1428e59cb4 100644 --- a/content/en/docs/cwgo/tutorials/client/example_thrift.md +++ b/content/en/docs/cwgo/tutorials/client/example_thrift.md @@ -33,7 +33,7 @@ service HelloService { > Note: If the project is located outside of GOPATH, gomod must be specified. GOPATH defaults to a path relative to GOPATH as the name, and gomod may not be specified. ```sh -cwgo client --type RPC --idl hello.thrift --service hellotest --module {{your_module_name}} +cwgo client --type RPC --idl hello.thrift --server_name hellotest --module {{your_module_name}} ``` ### Generate Code @@ -91,7 +91,7 @@ service HelloService { > Note: If the project is located outside of GOPATH, gomod must be specified. GOPATH defaults to a path relative to GOPATH as the name, and gomod may not be specified. ```sh -cwgo client --type HTTP --idl hello.thrift --service hellotest --module {{your_module_name}} +cwgo client --type HTTP --idl hello.thrift --server_name hellotest --module {{your_module_name}} ``` ### Generate Code diff --git a/content/en/docs/cwgo/tutorials/server/command.md b/content/en/docs/cwgo/tutorials/server/command.md index 71a66406e72..30ac28eef28 100644 --- a/content/en/docs/cwgo/tutorials/server/command.md +++ b/content/en/docs/cwgo/tutorials/server/command.md @@ -25,7 +25,8 @@ USAGE: cwgo server [command options] [arguments...] OPTIONS: - --service value Specify the service name. + --service value Specify the server name.(Not recommended) + --server_name value Specify the server name. --type value Specify the generate type. (RPC or HTTP) (default: "RPC") --module value, --mod value Specify the Go module name to generate go.mod. --idl value Specify the IDL file path. (.thrift or .proto) @@ -38,10 +39,13 @@ OPTIONS: --hex Add HTTP listen for Kitex. (default: false) --help, -h show help (default: false) ``` +## Attention +- service is not recommended and will be removed from v0.2.0 -## Specification -- service: Specify the service name for functions such as service registration and discovery +## Specification +- service: Specify the service name for functions such as service registration and discovery(Not recommended) +- server_name: Specify the service name for functions such as service registration and discovery - type: Specify the generation type, support parameters RPC and HTTP, default to RPC - module/mod: Specify the go mod name, which must be specified outside of GOPATH. In GOPATH, the default name is the path relative to GOPATH - idl: Specify the main IDL file path diff --git a/content/en/docs/cwgo/tutorials/server/example_pb.md b/content/en/docs/cwgo/tutorials/server/example_pb.md index fe3b7451285..c276b31b330 100644 --- a/content/en/docs/cwgo/tutorials/server/example_pb.md +++ b/content/en/docs/cwgo/tutorials/server/example_pb.md @@ -35,7 +35,7 @@ service HelloService { > Note: If the project is located outside of GOPATH, gomod must be specified. GOPATH defaults to a path relative to GOPATH as the name, and gomod may not be specified. ```sh -cwgo server --type RPC --idl hello.proto --service hellotest --module {{your_module_name}} -I . +cwgo server --type RPC --idl hello.proto --server_name hellotest --module {{your_module_name}} -I . ``` ### Generate Code @@ -161,7 +161,7 @@ service HelloService { > Note: If the project is located outside of GOPATH, gomod must be specified. GOPATH defaults to a path relative to GOPATH as the name, and gomod may not be specified. ```sh -cwgo server --type HTTP --idl hello.proto --service hellotest --module {{your_module_name}} +cwgo server --type HTTP --idl hello.proto --server_name hellotest --module {{your_module_name}} ``` ### Generate Code diff --git a/content/en/docs/cwgo/tutorials/server/example_thrift.md b/content/en/docs/cwgo/tutorials/server/example_thrift.md index 94a0f453a04..064f91c8c2b 100644 --- a/content/en/docs/cwgo/tutorials/server/example_thrift.md +++ b/content/en/docs/cwgo/tutorials/server/example_thrift.md @@ -31,7 +31,7 @@ service HelloService { > Note: If the project is located outside of GOPATH, gomod must be specified. GOPATH defaults to a path relative to GOPATH as the name, and gomod may not be specified. ```sh -cwgo server --type RPC --idl hello.thrift --service hellotest --module {{your_module_name}} +cwgo server --type RPC --idl hello.thrift --server_name hellotest --module {{your_module_name}} ``` ### Generate Code @@ -69,7 +69,7 @@ service HelloService { > Note: If the project is located outside of GOPATH, gomod must be specified. GOPATH defaults to a path relative to GOPATH as the name, and gomod may not be specified. ```sh -cwgo server --type HTTP --idl hello.thrift --service hellotest --module {{your_module_name}} +cwgo server --type HTTP --idl hello.thrift --server_name hellotest --module {{your_module_name}} ``` ### Generate Code diff --git a/content/zh/docs/cwgo/getting-started/_index.md b/content/zh/docs/cwgo/getting-started/_index.md index e50b72d1519..b2b542ce84a 100644 --- a/content/zh/docs/cwgo/getting-started/_index.md +++ b/content/zh/docs/cwgo/getting-started/_index.md @@ -109,7 +109,7 @@ cwgo 的具体使用请参考[命令行工具](/zh/docs/cwgo/tutorials/cli)。 4. 生成项目 layout ```shell - cwgo server -service=a.b.c -type HTTP -idl=idl/hello.thrift + cwgo server --server_name a.b.c --type HTTP --idl idl/hello.thrift -module {{your_module_name}} ``` 5. 编译运行 diff --git a/content/zh/docs/cwgo/tutorials/client/command.md b/content/zh/docs/cwgo/tutorials/client/command.md index 580593d90ab..7d03f9b7f7c 100644 --- a/content/zh/docs/cwgo/tutorials/client/command.md +++ b/content/zh/docs/cwgo/tutorials/client/command.md @@ -25,7 +25,8 @@ USAGE: cwgo client [command options] [arguments...] OPTIONS: - --service value Specify the service name. + --service value Specify the server name.(Not recommended) + --server_name value Specify the server name. --type value Specify the generate type. (RPC or HTTP) (default: "RPC") --module value, --mod value Specify the Go module name to generate go.mod. --idl value Specify the IDL file path. (.thrift or .proto) @@ -38,9 +39,12 @@ OPTIONS: --help, -h show help (default: false) ``` -## 详细参数 +## 注意 +- service 不建议使用,将在v0.2.0下架 -- service:指定服务名称,用于服务注册与发现等功能 +## 详细参数 +- service:指定服务名称,用于服务注册、服务发现等功能(不建议使用) +- server_name:服务名称,用于服务注册、服务发现等功能 - type:指定生成类型,支持参数 RPC、HTTP,默认为 RPC - module/mod:指定 go mod 名称,非 GOPATH 下必须指定,GOPATH 下默认以相对于 GOPATH 的路径作为名字 - idl:指定主 IDL 文件路径 diff --git a/content/zh/docs/cwgo/tutorials/client/example_pb.md b/content/zh/docs/cwgo/tutorials/client/example_pb.md index d9fb4f72b9e..2c3d0dab408 100644 --- a/content/zh/docs/cwgo/tutorials/client/example_pb.md +++ b/content/zh/docs/cwgo/tutorials/client/example_pb.md @@ -35,7 +35,7 @@ service HelloService { > Note: 项目位于非 GOPATH 下必须指定 gomod,GOPATH 下默认以相对于 GOPATH 的路径作为名字,可不指定 gomod。 ```sh -cwgo client --type RPC --idl hello.proto --service hellotest --module {{your_module_name}} -I . +cwgo client --type RPC --idl hello.proto --server_name hellotest --module {{your_module_name}} -I . ``` ### 生成代码 @@ -161,7 +161,7 @@ service HelloService { > Note: 项目位于非 GOPATH 下必须指定 gomod,GOPATH 下默认以相对于 GOPATH 的路径作为名字,可不指定 gomod。 ```sh -cwgo client --type HTTP --idl hello.proto --service hellotest --module {{your_module_name}} +cwgo client --type HTTP --idl hello.proto --server_name hellotest --module {{your_module_name}} ``` ### 生成代码 diff --git a/content/zh/docs/cwgo/tutorials/client/example_thrift.md b/content/zh/docs/cwgo/tutorials/client/example_thrift.md index 62555dd5b7b..44c70134877 100644 --- a/content/zh/docs/cwgo/tutorials/client/example_thrift.md +++ b/content/zh/docs/cwgo/tutorials/client/example_thrift.md @@ -33,7 +33,7 @@ service HelloService { > Note: 项目位于非 GOPATH 下必须指定 gomod,GOPATH 下默认以相对于 GOPATH 的路径作为名字,可不指定 gomod。 ```sh -cwgo client --type RPC --idl hello.thrift --service hellotest --module {{your_module_name}} +cwgo client --type RPC --idl hello.thrift --server_name hellotest --module {{your_module_name}} ``` ### 生成代码 @@ -91,7 +91,7 @@ service HelloService { > Note: 项目位于非 GOPATH 下必须指定 gomod,GOPATH 下默认以相对于 GOPATH 的路径作为名字,可不指定 gomod。 ```sh -cwgo client --type HTTP --idl hello.thrift --service hellotest --module {{your_module_name}} +cwgo client --type HTTP --idl hello.thrift --server_name hellotest --module {{your_module_name}} ``` ### 生成代码 diff --git a/content/zh/docs/cwgo/tutorials/server/command.md b/content/zh/docs/cwgo/tutorials/server/command.md index ff42ebe8495..c0a4cde87ae 100644 --- a/content/zh/docs/cwgo/tutorials/server/command.md +++ b/content/zh/docs/cwgo/tutorials/server/command.md @@ -25,7 +25,8 @@ USAGE: cwgo server [command options] [arguments...] OPTIONS: - --service value Specify the service name. + --service value Specify the server name.(Not recommended) + --server_name value Specify the server name. --type value Specify the generate type. (RPC or HTTP) (default: "RPC") --module value, --mod value Specify the Go module name to generate go.mod. --idl value Specify the IDL file path. (.thrift or .proto) @@ -38,10 +39,12 @@ OPTIONS: --hex Add HTTP listen for Kitex. (default: false) --help, -h show help (default: false) ``` +## 注意 +- service 不建议使用,将在v0.2.0下架 ## 详细参数 - -- service:指定服务名称,用于服务注册与发现等功能 +- service:指定服务名称,用于服务注册、服务发现等功能(不建议使用) +- server_name:服务名称,用于服务注册、服务发现等功能 - type:指定生成类型,支持参数 RPC、HTTP,默认为 RPC - module/mod:指定 go mod 名称,非 GOPATH 下必须指定,GOPATH 下默认以相对于 GOPATH 的路径作为名字 - idl:指定主 IDL 文件路径 diff --git a/content/zh/docs/cwgo/tutorials/server/example_pb.md b/content/zh/docs/cwgo/tutorials/server/example_pb.md index 1bad84ef3e5..8c0592a9f91 100644 --- a/content/zh/docs/cwgo/tutorials/server/example_pb.md +++ b/content/zh/docs/cwgo/tutorials/server/example_pb.md @@ -35,7 +35,7 @@ service HelloService { > Note: 项目位于非 GOPATH 下必须指定 gomod,GOPATH 下默认以相对于 GOPATH 的路径作为名字,可不指定 gomod。 ```sh -cwgo server --type RPC --idl hello.proto --service hellotest --module {{your_module_name}} -I . +cwgo server --type RPC --idl hello.proto --server_name hellotest --module {{your_module_name}} -I . ``` ### 生成代码 @@ -161,7 +161,7 @@ service HelloService { > Note: 项目位于非 GOPATH 下必须指定 gomod,GOPATH 下默认以相对于 GOPATH 的路径作为名字,可不指定 gomod。 ```sh -cwgo server --type HTTP --idl hello.proto --service hellotest --module {{your_module_name}} +cwgo server --type HTTP --idl hello.proto --server_name hellotest --module {{your_module_name}} ``` ### 生成代码 diff --git a/content/zh/docs/cwgo/tutorials/server/example_thrift.md b/content/zh/docs/cwgo/tutorials/server/example_thrift.md index b91d1951305..656cace8bfb 100644 --- a/content/zh/docs/cwgo/tutorials/server/example_thrift.md +++ b/content/zh/docs/cwgo/tutorials/server/example_thrift.md @@ -31,7 +31,7 @@ service HelloService { > Note: 项目位于非 GOPATH 下必须指定 gomod,GOPATH 下默认以相对于 GOPATH 的路径作为名字,可不指定 gomod。 ```sh -cwgo server --type RPC --idl hello.thrift --service hellotest --module {{your_module_name}} +cwgo server --type RPC --idl hello.thrift --server_name hellotest --module {{your_module_name}} ``` ### 生成代码 @@ -69,7 +69,7 @@ service HelloService { > Note: 项目位于非 GOPATH 下必须指定 gomod,GOPATH 下默认以相对于 GOPATH 的路径作为名字,可不指定 gomod。 ```sh -cwgo server --type HTTP --idl hello.thrift --service hellotest --module {{your_module_name}} +cwgo server --type HTTP --idl hello.thrift --server_name hellotest --module {{your_module_name}} ``` ### 生成代码 From e1e1b9aa27fcabc2e06fe247b3a70fbbf2b8c8fd Mon Sep 17 00:00:00 2001 From: yuxialuozi <3159452953@qq.com> Date: Sun, 16 Jun 2024 19:59:08 +0800 Subject: [PATCH 2/3] feat:a built-in template description --- .../tutorials/templete-extension/_index.md | 29 ++++++++++++++++++ .../tutorials/templete-extension/_index.md | 29 ++++++++++++++++++ .../cwgo_templete-extension_standard-v2.png | Bin 0 -> 6546 bytes 3 files changed, 58 insertions(+) create mode 100644 static/img/docs/cwgo_templete-extension_standard-v2.png diff --git a/content/en/docs/cwgo/tutorials/templete-extension/_index.md b/content/en/docs/cwgo/tutorials/templete-extension/_index.md index 58f7c35059c..446b06e622b 100644 --- a/content/en/docs/cwgo/tutorials/templete-extension/_index.md +++ b/content/en/docs/cwgo/tutorials/templete-extension/_index.md @@ -4,6 +4,35 @@ linkTitle: "Template Extension" weight: 1 description: > --- +## 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` + + 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. diff --git a/content/zh/docs/cwgo/tutorials/templete-extension/_index.md b/content/zh/docs/cwgo/tutorials/templete-extension/_index.md index 34a3f856ab6..622ba87b468 100644 --- a/content/zh/docs/cwgo/tutorials/templete-extension/_index.md +++ b/content/zh/docs/cwgo/tutorials/templete-extension/_index.md @@ -4,6 +4,35 @@ linkTitle: "模板拓展" weight: 1 description: > --- +## 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` + + cwgo 工具也支持传递自己的模板,模版语法为 go template 的语法。cwgo 也欢迎用户贡献自己的模板。由于 RPC 和 HTTP 概念不同,其对应的模版变量也有一些差异,详细请参考下文。 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 0000000000000000000000000000000000000000..ff613ecac2f2ef45760bedaa943a43eeb9b9cc00 GIT binary patch literal 6546 zcmdU!c{tST-^Xu?hC)NBk-%j%_S66oxE^ViZ}D7JG~(%`vu^LZmE{CA(0{ z7Ht|LvhOX%7G~^Y_xo}>=c%4^p68t3b^V^}dj4`<_jkTC-?{IX_viKbOb}id%fl_i z4FKTL!l@eoz`hRvHWe5lfQ-Aus+YYl`r>mn;uuOxtN{?~+O+odCQpJfirmXXIi!^!-(WcV+ zR)5Wjo|nV-aa`J;=>TwmrQd1z`R;vOeRD>cOqDic;( zm6s;VvwG&2TH<&J&V4=2DR-Ba@7&u2(h8v$5abJ&N8cAnuPiB3C#63e7Ww&^n^oV- zA?#7*THPdLhmoo!q^*0Nab~lLmlF)&Hy4D}k3Oz_P{&&Xvrnii&$)ELytq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?drS_e0MGb)J>^yYe2^nFr6`JiO&< z=YG!|+Pz35KnMOgNUtj(-%{-Pqsy~LNufnP49;v^ItK9wqEMuJJHoKmW`>y1ZXut6g3af$OL743KD-vH7cP zZ7q|C#N8J6LVt?K8`#eV9`^gZ*PA5uIl<@T1B sYsk!Tq#~wdzoF`z>G$0C-QDDh%234s1% Date: Wed, 19 Jun 2024 10:28:32 +0800 Subject: [PATCH 3/3] fig:modify the description location of the template --- .../tutorials/templete-extension/_index.md | 58 +++++++++---------- .../tutorials/templete-extension/_index.md | 57 +++++++++--------- 2 files changed, 55 insertions(+), 60 deletions(-) diff --git a/content/en/docs/cwgo/tutorials/templete-extension/_index.md b/content/en/docs/cwgo/tutorials/templete-extension/_index.md index 446b06e622b..3ac7c12d90c 100644 --- a/content/en/docs/cwgo/tutorials/templete-extension/_index.md +++ b/content/en/docs/cwgo/tutorials/templete-extension/_index.md @@ -4,36 +4,6 @@ linkTitle: "Template Extension" weight: 1 description: > --- -## 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` - - - 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: @@ -100,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 @@ -156,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 622ba87b468..82a14f32dd0 100644 --- a/content/zh/docs/cwgo/tutorials/templete-extension/_index.md +++ b/content/zh/docs/cwgo/tutorials/templete-extension/_index.md @@ -4,36 +4,6 @@ linkTitle: "模板拓展" weight: 1 description: > --- -## 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` - - - cwgo 工具也支持传递自己的模板,模版语法为 go template 的语法。cwgo 也欢迎用户贡献自己的模板。由于 RPC 和 HTTP 概念不同,其对应的模版变量也有一些差异,详细请参考下文。 如需传递自定义模板,请给命令添加 `-template` 参数,如: @@ -100,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 结构体含义