
GOENUM
Go enum code generation that enables different business domains to share common enum names like OK, ERROR, PENDING without naming conflicts through namespace isolation.
CHINESE README
中文说明
Features
🔒 Namespace Isolation - Each domain has its own enum space, preventing naming conflicts
⚡ Type Validation - Auto-generated validation methods ensure value correctness
🎯 Clean Code - Intuitive syntax that matches business logic patterns
✅ Compile Protection - Catch enum misuse at build time, not runtime
🌍 Multi-Language - Generate enums using any language characters
Installation
go get github.com/yyle88/goenum
Usage
Go lacks true enum namespaces. Different domains can't share common value names like OK, ERROR, PENDING.
Before: Verbose Prefixes Required
type PackageStatus string
const (
PackagePending PackageStatus = "PENDING"
PackageConfirmed PackageStatus = "CONFIRMED"
PackageShipped PackageStatus = "SHIPPED"
PackageDelivered PackageStatus = "DELIVERED"
)
type PaymentStatus string
const (
PaymentPending PaymentStatus = "PENDING"
PaymentFailed PaymentStatus = "FAILED"
PaymentSuccess PaymentStatus = "SUCCESS"
PaymentRefund PaymentStatus = "REFUND"
)
// Verbose switch statements with long prefixes
func processPackage(status string) {
switch PackageStatus(status) {
case PackagePending:
// handle pending
case PackageConfirmed:
// handle confirmed
case PackageShipped:
// handle shipped
case PackageDelivered:
// handle delivered
}
}
func processPayment(status string) {
switch PaymentStatus(status) {
case PaymentPending:
// handle pending
case PaymentFailed:
// handle failed
case PaymentSuccess:
// handle success
case PaymentRefund:
// handle refund
}
}
With GOENUM: Clean Namespace Methods
// Each domain gets its own clean namespace
func processPackage(status string) {
switch PackageStatusEnum(status) {
case PackageStatus.Pending():
// handle pending
case PackageStatus.Confirmed():
// handle confirmed
case PackageStatus.Shipped():
// handle shipped
case PackageStatus.Delivered():
// handle delivered
}
}
func processPayment(status string) {
switch PaymentStatusEnum(status) {
case PaymentStatus.Pending():
// handle pending
case PaymentStatus.Failed():
// handle failed
case PaymentStatus.Success():
// handle success
case PaymentStatus.Refund():
// handle refund
}
}
Multi-Language Support
GOENUM supports enum generation in multiple languages:
// Chinese enum usage example
func processTask(status string) {
taskStatus := TaskStatusEnum(status)
switch taskStatus {
case TaskStatus.C待处理():
// handle pending task
case TaskStatus.C已确认():
// handle confirmed task
case TaskStatus.C进行中():
// handle active task
case TaskStatus.C已完成():
// handle completed task
}
}
// Traditional Chinese enum example
func processPermission(status string) {
permStatus := PermissionStatusEnum(status)
switch permStatus {
case PermissionStatus.C開啟():
// handle enabled permission
case PermissionStatus.C關閉():
// handle disabled permission
}
}
// Japanese enum example
func processConnection(status string) {
connStatus := ConnectionStatusEnum(status)
switch connStatus {
case ConnectionStatus.C接続():
// handle connected
case ConnectionStatus.C切断():
// handle disconnected
case ConnectionStatus.C待機():
// handle waiting
}
}
// Korean enum example
func processGame(status string) {
gameStatus := GameStatusEnum(status)
switch gameStatus {
case GameStatus.C시작():
// handle game start
case GameStatus.C종료():
// handle game end
case GameStatus.C일시정지():
// handle game pause
}
}
Examples: See examples
📄 License
MIT License. See LICENSE.
🤝 Contributing
Contributions are welcome! Report bugs, suggest features, and contribute code:
- 🐛 Found a bug? Open an issue on GitHub with reproduction steps
- 💡 Have a feature idea? Create an issue to discuss the suggestion
- 📖 Documentation confusing? Report it so we can improve
- 🚀 Need new features? Share your use cases to help us understand requirements
- ⚡ Performance issue? Help us optimize by reporting slow operations
- 🔧 Configuration problem? Ask questions about complex setups
- 📢 Follow project progress? Watch the repo for new releases and features
- 🌟 Success stories? Share how this package improved your workflow
- 💬 General feedback? All suggestions and comments are welcome
🔧 Development
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage interface).
- Clone: Clone the forked project (
git clone https://github.com/yourname/repo-name.git).
- Navigate: Navigate to the cloned project (
cd repo-name)
- Branch: Create a feature branch (
git checkout -b feature/xxx).
- Code: Implement your changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...) and follow Go code style conventions
- Documentation: Update documentation for user-facing changes and use meaningful commit messages
- Stage: Stage changes (
git add .)
- Commit: Commit changes (
git commit -m "Add feature xxx") ensuring backward compatible code
- Push: Push to the branch (
git push origin feature/xxx).
- PR: Open a pull request on GitHub (on the GitHub webpage) with detailed description.
Please ensure tests pass and include relevant documentation updates.
🌟 Support
Welcome to contribute to this project by submitting pull requests and reporting issues.
Project Support:
- ⭐ Give GitHub stars if this project helps you
- 🤝 Share with teammates and (golang) programming friends
- 📝 Write tech blogs about development tools and workflows - we provide content writing support
- 🌟 Join the ecosystem - committed to supporting open source and the (golang) development scene
Happy Coding with this package! 🎉
GitHub Stars
