-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
improve gf gen ctrl gets structs info way #3066
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
Conversation
AST 可以用 ast.Inspect 去遍历,是不是更好一点
|
AST can be traversed using ast.Inspect. Isn’t it better?
|
// ignore struct name that match a request, but has no g.Meta in its body. | ||
if !gstr.Contains(structBody, `g.Meta`) { | ||
continue | ||
} | ||
// remove end "Req" | ||
methodName = gstr.TrimRight(methodName, "Req") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gstr.TrimRightStr
@oldme-git It is awesome! |
@oldme-git It is awesome! |
@oldme-git There's another important improvement: adding unit testing case for command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see the comments.
@whileW 我觉得使用for循环比Inspect更加的清晰灵活,而且GetStructs()是封装的方法,不能把"Req"直接拿进来判断 |
@whileW I think using a for loop is clearer and more flexible than Inspect, and GetStructs() is an encapsulated method, and "Req" cannot be directly used for judgment. |
好吧 |
All right |
@gqcn 强哥,你看一下geo ctrl的单测 |
@gqcn Brother Qiang, take a look at the single test of geo ctrl |
|
||
import "context" | ||
|
||
var ctx = context.Background() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不用单独增加这个文件,可以将这个变量写到cmd_gen_ctrl_test.go
文件中。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个变量被cmd_gen_dao_test.go占用了
type IArticleV2 interface { | ||
Create(ctx context.Context, req *v2.CreateReq) (res *v2.CreateRes, err error) | ||
Update(ctx context.Context, req *v2.UpdateReq) (res *v2.UpdateRes, err error) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要把这个文件还有控制器目录中,生成的文件都加入.gitignore
里面,不要直接提交。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里的文件用作expect
#3063
之前使用正则表达式获取结构体信息,现在改为使用 AST 获取结构体信息,这样更为合理和精确。