Enum type in Go

This ‘Season’ type can be used like any other type in go, but with limited allowed values.

package main

type Season int

const (
  Spring Season = iota
  Summer
  Autumn
  Winter
)

func main() {
  var season Season
  season = Summer
}Code language: JavaScript (javascript)

CategoriesGo

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.