> Whenever I have to do code generation in my language of choice, I feel that the language should be able to do that without having to generate code.
A good use of code generation is to relieve yourself the burden of hand-writing repetitive mapping code, especially when modelling the database structure in application code. This is a perfect use case for that. Same is true for generating a client to some external API.
Otherwise I'm inclined to agree with you. A few times, I've written code generators before and realised I could've gotten away with some generic programming.
But that has its own set of gotchas and caveats. Though go has support for some generic programming now.