A Go code generator that creates type-safe enumerations with useful methods from simple type declarations.
go-enum is a command-line tool that generates type-safe enumeration types for Go programs from simple commented type declarations. It automates the creation of enums with string conversion, JSON marshaling, SQL integration, and other useful methods, eliminating the need for repetitive boilerplate code. The tool uses a comment-based syntax like `// ENUM(...)` to define enum values and supports both integer and string base types.
Go developers who need robust, type-safe enums in their applications, particularly those working on projects that require serialization (JSON), database interaction (SQL), or consistent enum handling across different layers of an application.
Developers choose go-enum over manual implementation or basic generators because it provides a comprehensive set of features out-of-the-box, including JSON marshaling, SQL integration, and custom template support, while maintaining a simple and flexible declaration syntax. It saves significant development time by automating error-prone boilerplate and ensures consistency across enum-related code.
An enum generator for go
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Generates enums with string conversion, JSON marshaling, SQL integration, and more, reducing boilerplate as shown in the Key Features and Quick Start examples.
Uses simple comment-based declarations like // ENUM(...) for easy enum definition, making it readable and maintainable per the Syntax section.
Supports int, string, and other base types, ensuring type-safe enumerations with proper Go typing, evidenced in examples with int and string enums.
Offers custom templates and numerous flags (e.g., --jsonpkg, --no-iota) for tailored code generation, detailed in Command Options and Recent Features.
Integrates seamlessly with go generate and Go 1.24+ tool dependencies, facilitating automated code generation in projects, as explained in Adding it to your project.
With over 20 command-line flags, setting up enums correctly can be overwhelming and error-prone for simple use cases, as seen in the lengthy Command Options list.
Produces extensive code with maps and auxiliary functions, adding unnecessary bulk if features like case-insensitive parsing are not needed, evident in the example output.
Requires installation and management of the go-enum tool, complicating build processes and introducing potential versioning issues, as highlighted in the Installation section.