Put go generate directive at the top: //go:generate go run ../main.go. Remember that you may have to change the path to main.go file.
Create object interface definition.
Add key-value entry to definitionMapping in main.go:
key should be created file name (for database_role_def.go example file: "database_role_def.go")
value should be created definition (like for database_role_def.go example file: DatabaseRole)
You are all set to run generation.
Invoking generation
To invoke example generation (with first cleaning all the generated files) run:
make clean-generator-poc run-generator-poc
Next steps
Essentials
use DSL to build object definitions (from branch go-builder-dsl) - ideally leave two options of defining objects and proceed with generation based on definition provided
differentiate between different actions implementations (now only Create and Alter has been considered, Show on the other hand has totally different implementation)
generate structs for Show and ShowID
handle arrays
handle more validation types
Improvements
automatic names of nested structs (e.g. DatabaseRoleRename)
check if generating with package name + invoking format removes unnecessary qualifier
consider merging templates StructTemplate and OptionsTemplate (requires moving Doc to Field)
add unit tests to this generator
Known issues
spaces in templates (especially nested validations)