Jennifer is a code generator for Go that provides a programmatic API for constructing Go source code.
The tool solves the problem of writing Go code generation logic by hand, which is error-prone and verbose. Instead of string concatenation or template manipulation, Jennifer offers a fluent API where developers construct code through method calls that represent Go language constructs. The generator handles details like import management automatically, including detecting when packages conflict and renaming them as needed, and recognizing standard library packages without requiring aliases.
Jennifer suits projects that need to generate Go code as part of their build or development process. The tool works well for developers who prefer type-safe, composable code generation over templates or string builders. It includes rendering methods for identifiers, keywords, operators, control flow statements, collections, literals, comments, and generics. For testing, code can be rendered using the fmt package, though the README notes this is not recommended for production use due to panic behavior on errors; instead, the File.Render or File.Save methods are preferred for production scenarios.
The project maintains a comprehensive suite of examples in its godoc documentation and demonstrates real-world usage through several generators built with it. The codebase includes genjen, which generates much of Jennifer itself using structured data, showing the tool's capability to bootstrap its own development. The maintainer actively welcomes engagement through issues, direct communication, and code review offers.