This method applies key fields when declaring a structure.
For example, struct:
type SomeType struct { Field1 string Field2 bool _ struct{} }
can only be declared using key fields:
// ALLOWED: bar := SomeType{Field1: "hello", Field2: "true"} // COMPILE ERROR: foo := SomeType{"hello", true}
One reason for this is to include additional fields in the structure in the future without breaking existing code.
source share