Created
October 23, 2011 17:26
-
-
Save kylelemons/1307606 to your computer and use it in GitHub Desktop.
Enumerations in Go with string names
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type day int | |
const ( | |
Sunday day = iota | |
Monday | |
Tuesday | |
Wednesday | |
Thursday | |
Friday | |
Saturday | |
) | |
var dayNames = [...]string{ | |
"Sunday", "Monday", "Tuesday", "Wednesday", | |
"Thursday", "Friday", "Saturday", | |
} | |
func (d day) String() string { | |
return dayNames[d] | |
} | |
func main() { | |
fmt.Println(Tuesday) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment