我如何在golang中进行枚举?

ste*_*iss 2 go

我有

const (
  BlahFoo = 1 << iota
  MooFoo
)
Run Code Online (Sandbox Code Playgroud)

然后

type Cluster struct {
  a  int
  b  int
}
Run Code Online (Sandbox Code Playgroud)

我希望Cluster.a只是BlahFoo或MooFoo

我该如何执行?

Zik*_*kes 7

type FooEnum int

const (
  BlahFoo FooEnum = 1 << iota
  MooFoo
)

type Cluster struct {
  a FooEnum
  b int
}
Run Code Online (Sandbox Code Playgroud)