jmattheis / goverter

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

Add raw code to generated file #113

Open jmattheis opened 10 months ago

jmattheis commented 10 months ago

Sometimes you want to add some generic code, but only after the generator ran. E.g. when you want to have a variable that has an initialized converter impl.

var Converter Converter = &ConverterImpl{}

Having this inside the conversion interface will cause compile errors. This issue proposes a new setting called goverter:output:raw where you can define raw code that will be added to the generation file.

Example:

// goverter:converter
// goverter:output:file ./output.gen.go
// goverter:output:raw func init() {
// goverter:output:raw     converter = &converterImpl{}
// goverter:output:raw }
type Converter interface {}

Please :+1: this issue if you like this functionality. If you have a specific use-case in mind, feel free to comment it.