Constants

Constants in Go are just that — constant. They are created at compile time,and can only be numbers, strings, or booleans; const x = 42 makes xa constant. You can useiota5 to enumerate values.

  1. const (
  2. a = iota
  3. b
  4. )

The first use of iota will yield 0, so a is equal to 0. Whenever iota isused again on a new line its value is incremented with 1, so b has a value of 1.Or, as shown here, you can even let Go repeat the use of iota. You may alsoexplicitly type a constant: const b string = "0". Now b is a string typeconstant.