For a use case like this, it may be useful to use a string constant so it can be marshaled into a JSON string. In the following example, []Base{A,C,G,T}
would get marshaled to ["adenine","cytosine","guanine","thymine"]
.
type Base string
const (
A Base = "adenine"
C = "cytosine"
G = "guanine"
T = "thymine"
)
When using iota
, the values get marshaled into integers. In the following example, []Base{A,C,G,T}
would get marshaled to [0,1,2,3]
.
type Base int
const (
A Base = iota
C
G
T
)
Here's an example comparing both approaches: