💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
Go语言现阶段没有枚举类型,但是可以使用 const 常量配合上一节《Go语言常量》中介绍的 iota 来模拟枚举类型。 ~~~ type Weapon int const ( Arrow Weapon = iota // 开始生成枚举值, 默认为0 Shuriken SniperRifle Rifle Blower ) // 输出所有枚举值 fmt.Println(Arrow, Shuriken, SniperRifle, Rifle, Blower) // 使用枚举类型并赋初值 var weapon Weapon = Blower fmt.Println(weapon) ~~~ 输出如下: ~~~ 0 1 2 3 4 4 ~~~