Goenums: Type Safe Enum Generator for Go

https://news.ycombinator.com/rss Hits: 5
Summary

goenums goenums addresses Go's lack of native enum support by generating comprehensive, type-safe enum implementations from simple constant declarations. Transform basic iota based constants into feature-rich enums with string conversion, validation, JSON handling, database integration, and more. Installation go install github.com/zarldev/goenums@latest Documentation Documentation is available at https://zarldev.github.io/goenums. Table of Contents Key Features Type Safety: Wrapper types prevent accidental misuse of enum values String Conversion: Automatic string representation and parsing JSON Support: Built-in marshaling and unmarshaling Database Integration: SQL Scanner and Valuer implementations Validation: Methods to check for valid enum values Iteration: Modern Go 1.21+ iteration support with legacy fallback Extensibility: Add custom fields to enums via comments Exhaustive Handling: Helper functions to ensure you handle all enum values Zero Dependencies: Completely dependency-free, using only the Go standard library Usage $ goenums -h ____ _____ ___ ____ __ ______ ___ _____ / __ '/ __ \/ _ \/ __ \/ / / / __ '__ \/ ___/ / /_/ / /_/ / __/ / / / /_/ / / / / / (__ ) \__, /\____/\___/_/ /_/\__,_/_/ /_/ /_/____/ /____/ Usage: goenums [options] filename Options: -help, -h Print help information -version, -v Print version information -failfast, -f Enable failfast mode - fail on generation of invalid enum while parsing (default: false) -legacy, -l Generate legacy code without Go 1.23+ iterator support (default: false) -insensitive, -i Generate case insensitive string parsing (default: false) -verbose, -vv Enable verbose mode - prints out the generated code (default: false) -output, -o string Specify the output format (default: go) Features Expanded Custom String Representations Handle custom string representations defined in the comments of each enum. Support for enum strings with spaces is supported by adding the alternative name in double quotes: Standard Name When ...

First seen: 2025-04-26 22:12

Last seen: 2025-04-27 02:12