jmattheis / goverter

Generate type-safe Go converters by simply defining an interface
https://goverter.jmattheis.de/
MIT License
496 stars 46 forks source link

[Questions] When generating files, is it possible to generate independent files for each struct ? #46

Closed shuqingzai closed 1 year ago

shuqingzai commented 1 year ago

Have you read the project readme?

Describe your question A clear and concise description of what the question is. Include errors and go source files.

Now it seems that all defined interface generation structures will be in the same file generated/generated.go, but if it is developed by multiple people, my partner and I will define different interface generators, which will easily cause Git conflicts. If each structure can be generated independently file that's great

jmattheis commented 1 year ago

I don't understand your problem. Are the merge conflicts in the generated code? To solve these conflicts, you only have to rerun goverter. Additionally, it's recommended to not commit generated code, as it can easily get outdated.

You could put the generators into different packages and executed goverter for both packages.

shuqingzai commented 1 year ago

There is also a more serious problem. As time goes by, more and more interfaces are defined and converted, and the generated file will be very large, because the generated struct will be merged into one file, which is not easy to read the code

jmattheis commented 1 year ago

Code readability is subjective, I mostly find it easy navigating through the single file because it's possible to navigate to the implementing method on the Converter interface.

I don't think it's worth the effort to change goverter to create separate files for the converter method implementations.

jmattheis commented 8 months ago

This feature was added in v1.0.0. See output:file