Struct — the kind for named fields: properties fixes each field, and the struct is closed (unlisted keys rejected) unless it adds a values tail. A map has no named fields — every value matches one values schema. Distinct kinds since struct was promoted; naming fields on a map is the pre-struct legacy form.
A struct is a map whose keys are known in advance. Its schema lists them under properties, one property per field — the field's value schema, whether it is required, and a description — and is closed unless it also gives values, the schema every extra key must satisfy. At the data-model level a struct is still a map; the distinction lives in the schema, where it does the work: a form knows which fields to show, a validator knows which keys are stray, a generated type gets named members.
Use a struct when the fields have names and meanings of their own: a person has a name and an age, a Change has a genesis and deps. Use a map when the keys are data: word → count, key → value. The reference examples are Example: Person for a struct and Example: Counts for a map.
Do you like what you are reading? Subscribe to receive updates.
Unsubscribe anytime