Struct literals
suggest changeA value of a struct type can be written using a struct literal that specifies values for its fields.
type Point struct { X, Y int }
p := Point{1, 2}
The example above lists every field, in order. That is brittle, because the order has to match the type. More often, a struct is initialized by listing some or all of the field names and their values.
anim := gif.GIF{LoopCount: nframes}
Omitted fields are set to the zero value for their type.
Note: the two forms cannot be mixed in the same literal.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents