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

Add "AllTypes" variable to store all struct types generated by goctl #4647

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

wenxichang
Copy link

为生成的types.go文件添加一个AllTypes []reflect.Type,这样主框架可以枚举到所有生成的类型,这让统一检查这些类型成为可能(例如lint工具,静态检查有时不好使:规范上要求实现Validate来较验数据,tag上标注好但代码上遗漏了)

@kevwan
Copy link
Contributor

kevwan commented Feb 13, 2025

Don't get your purpose, would you please describe it in details?

@wenxichang
Copy link
Author

我需要为所有api开发一个统一的较验入口,现在的做法是为所有的types中的结构添加Validate,这项工作可能遗漏——在一个有几百个API的项目中,我非常需要一个lint工具。
虽然可以静态分析代码获得所有的结构体,却无法感知它们在运行时是否实现了较验,所以运行时的检查尤为重要。

另外,我们的openAPI还有一些规范,例如json属性的取名规范,在提供AllTypes的情况下,便能够使用reflect遍历所有json tag来检查。没有枚举出所有类型的情况下,实现起来非常麻烦。

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


I need to develop a unified verification portal for all APIs, and now the approach is to add Validate to the structure in all types, this work may be missing - in a project with hundreds of APIs, I really need a lint tool.
Although all structures can be obtained by static analysis of the code, it is impossible to sense whether they have achieved validity at runtime, so runtime checking is particularly important.

In addition, our openAPI also has some specifications, such as the naming specification of json attributes. When providing AllTypes, we can use reflect to traverse all json tags to check. Without enumeration of all types, it is very troublesome to implement.

@kevwan
Copy link
Contributor

kevwan commented Feb 22, 2025

Would you please give me an example on how to use it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants