jmattheis / goverter

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

How do I avoid / handle compilation errors due to changes? #130

Closed irieimperator closed 8 months ago

irieimperator commented 8 months ago

Have you read the project documentation?

Describe your question Hi, thanks for this great package, it is extremely useful to avoid having to write annoying boilerplate! 🙂

I currently have a kind of "chicken and egg problem" when using it: goverter only works if the code compiles successfully, right? I have initially run goverter and use the methods in the code. Now I change certain types and also adapt the converter methods accordingly. Due to these changes the project has errors because it still uses the old types. So I would have to run goverter so that everything is correct and compiles again - but exactly that does not work because goverter does not run.

Have I not understood something fundamental? How do you recommend resolving the conflict? Thanks mate!

jmattheis commented 8 months ago

If you are defining the output:file in the same directory as the converter interface, then this guide lists two possibles fixes for compile errors: https://goverter.jmattheis.de/guide/output-same-package

If you have a different problem, then could you create a minimal example when something breaks with compile errors? Generally you can define the goverter build constraint to specifically exclude files from the goverter compilation but keep in mind that the not excluded files must compile on their own without the excluded files. See https://goverter.jmattheis.de/reference/build-constraint

irieimperator commented 8 months ago

Wow, thanks for the quick help! Your tips made me take a closer look at my run command and the CLI options - the solution in my case was to explicitly define the package in which the converter interfaces are defined instead of "./..." as the package import pat, uff...

I was too lazy the first time I tried it and then too blind...

So, nevermind, the library is great, thank you very much! ❤️