cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
5.31k stars 520 forks source link

hertz代码生成工具生成的model内容 #1049

Closed xiaolibuzai-ovo closed 9 months ago

xiaolibuzai-ovo commented 9 months ago

Describe the Question

使用hz代码生成工具生成的model里面有很多和struct无关的内容,请问他们的实际作用是什么?是否能只根据idl来生成model呢?(ps:我记得之前字节内部的hertz就是只生成struct的)

这是我的thrift idl

// idl/hello.thrift
namespace go hydrox.ai

struct HelloReq {
    1: string name (api.body="name") // 添加 api 注解为方便进行参数绑定
    2: string test_aba  (api.body="testAba")
}

struct HelloResp {
    1: string RespBody;
}

service HelloService {
    HelloResp HelloMethod(1: HelloReq request) (api.get="/hello");
}

hz命令

 hz model --idl ./test.thrift

生成model中的内容

image

虽然他生成的内容已经包含了我需要的struct,并且很好的帮我我减去编写struct的时间,但是我还是比较好奇他生成的其他内容,对于http api来说的作用是什么,以及是否可以去掉? thanks

A clear and concise description of what the question is.

Reproducible Code

Please construct a minimum complete and reproducible example for us to get the same error. And tell us how to reproduce it like how you send a request or send what request.

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your question.

Hertz version:

Please provide the version of Hertz you are using.
最新版本

Environment:

The output of go env.

Additional context

Add any other context about the question here.

li-jin-gou commented 9 months ago

这个可以关闭的 @xiaolibuzai-ovo

li-jin-gou commented 9 months ago

update 和 new 时使用 -t=template=slim 即可,额外生成的是 thrift 编解码函数, hertz 是不需要使用的