{"repo":"orsinium-labs/enum","free":true,"listed":false,"github":"https://github.com/orsinium-labs/enum","clone":"git clone https://github.com/orsinium-labs/enum.git","description":"Type safe enums for Go without code generation or reflection","language":"Go","stars":462,"topics":["enum","enum-to-string","enums","generics","go","golang","metaprogramming","reflection","string-to-enum"],"license":"MIT","category":"dev-tools","readme_excerpt":"enum [📄 docs ] [🐙 github ] [❤️ sponsor ] Type safe enums for Go without code generation or reflection. 😎 Features: Type-safe, thanks to generics. No code generation. No reflection. Well-documented, with working examples for every function. Flexible, supports both static and runtime definitions. Zero-dependency. 📦 Installation 🛠️ Usage Define: Parse a raw value ( nil is returned for invalid value): Compare enum members: Accept enum members as function arguments: Loop over all enum members: Ensure that the enum member belongs to an enum (can be useful for defensive programming to ensure that the caller doesn't construct an enum member manually): Define custom methods on enum members: Dynamically create enums to pass multiple members in a function: Enum members can be any comparable type, not just strings: If the enum has lots of members and new ones may be added over time, it's easy to forget to register all members in the enum. To prevent this, use enum.Builder to define an enum: 🤔 QnA 1. What happens when enums are added in Go itself? I'll keep it alive until someone uses it but I expect the project popularity to quickly die out when there is native language support for enums. When you can mess with the compiler itself, you can do more. For example, this package can't provide an exhaustiveness check for switch statements using enums (maybe only by implementing a linter) but proper language-level enums would most likely have it. 1. Is it reliable? Yes, pretty much. It ha","default_branch":null,"files":null,"tree":[],"storefront":"/r/orsinium-labs","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/orsinium-labs/enum/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}