Usage of named aliases for types in an effort to emulate enumeration behavior from other languages can cause issues.
Using a named type for an alias gives the illusion of control, but since a literal value can be placed as it matches the type, it doesn't really do anything but provide an additional layer of abstraction.
Example:
A possible example of using Iota, while still providing a string value output is shown here: playground.
This protects the code to do use an iota constant, while still ensuring a simple string value represents it.
NOTE: I believe this is what stringer
package trys to simplify, in you can generate the basic structure illustrated above with less effort by having generation of these sets of constants done automatically.
- Stringer to generate iota based enums dynamically.
- Don't use enum.