Skip to content

Instantly share code, notes, and snippets.

@kylelemons
Created October 23, 2011 17:26
Show Gist options
  • Save kylelemons/1307606 to your computer and use it in GitHub Desktop.
Save kylelemons/1307606 to your computer and use it in GitHub Desktop.
Enumerations in Go with string names
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