Skip to content

Instantly share code, notes, and snippets.

@soundTricker
Created June 13, 2014 00:36
Show Gist options
  • Save soundTricker/4d90b81bb25f4fac5501 to your computer and use it in GitHub Desktop.
Save soundTricker/4d90b81bb25f4fac5501 to your computer and use it in GitHub Desktop.
[覚書]Goでenumっぽいので表示名を作る ref: http://qiita.com/soundTricker/items/f9d2c3e3902e8ddd4a98
type EnumType int
const (
One EnumType = iota //初期値を0以外にする場合は iota+1とかで調整
Tow
Three
)
//EnumType の文字列表現
var enumTypes = [...]string{
"一",
"二",
"三",
}
//Enum→string
func (e EnumType) String() string { return enumTypes[e]}
//string→Enum こっちは微妙
func ParseEnumType(name string) EnumType {
for i, display := range enumTypes {
if name == display {
return EnumType(i)
}
}
return One
}
//int → Enum は EnumType(int)とかでやるはず
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment