How to create an enum and iterate over it
问题 I'm trying to replicate the Java enums in Go. I would like to define an enum and then iterate over it to do some validations. Something like this in java public enum Direction { NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST } And the I would like to iterate over it, like this: for (Direction dir : Direction.values()) { // do what you want } Is there a similar way to achieve this in Golang, I'm thinking in using structs but I don't think it's the best way. Any ideas? 回答1