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

设计优化:代码逻辑解耦 #4

Open
hitzhangjie opened this issue Jun 20, 2020 · 1 comment
Open

设计优化:代码逻辑解耦 #4

hitzhangjie opened this issue Jun 20, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@hitzhangjie
Copy link
Owner

hitzhangjie commented Jun 20, 2020

gorpc create代码生成为例,过程中涉及到了:

  • 命令行参数的解析; done,不需要每次PreRunE、RunE之前显示cmd.ParseFlags(...), cobra框架里面已经做了
  • pb文件的解析; done,依然通过jhump/protoreflect
  • 工作目录的准备; todo,这个要看下--output有没有什么不安全的地方
  • 代码生成; todo,代码模板再进一步简化下
  • protoc生成; done,这个没什么要更新的
  • 依赖的pb文件的protoc生成; todo,由于语言相关,依赖对应的插件,这里要通过插件形式来实现
  • 各个语言后置的一些特殊逻辑;
    • 各个扩展项如validate、swagger的一些代码生成逻辑`
    • 后续如何扩展? done, using --plugins=validator+swagger instead of --swagger --validator

按照最初我的设计:

  • 这个工具是语言无关的,各个语言相关的特殊逻辑,应该通过各自的模板来解决
    实际情况是,部分同学对pb细节、gotemplate掌握的不深入,只知道在代码里面堆砌代码来解决,代码中侵入了各个语言特有的逻辑;
  • 这个工具应该支持一些灵活的脚本,如自定义的mv、copy支持,允许代码生成后执行一些简单的处理,避免侵入工具代码中
    这部分,对应的同学一直拖,拖到现在也没有实现,sad
  • 后续如何扩展插件,原先的设计中确实考虑不太周到,需要提供一个更好的方式来支持扩展,如针对swagger.proto的处理,能否不通过侵入代码的形式来支持到,肯定是可以的。
@hitzhangjie
Copy link
Owner Author

hitzhangjie commented Jun 20, 2020

parser/desc.go:

如下结构可以进行适当调整,携带自定义扩展的proto对应的解析信息,模板里面完成对应的逻辑,不需要侵入到代码中。如携带原始的desc.FileDescriptor信息

type FileDescriptor struct{
     ....
}

@hitzhangjie hitzhangjie added the enhancement New feature or request label Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant