This is a very similar data type as structs, but it has certain differences.
The keys and values of the map are statically typed (All the same type!)
Here's a definition: m map[string] string
where the m
is the argument name and the [string]
is the type of the map.
- All keys must be the same type
- All values must be the same type
- Keys are indexed, we can add an iterator over them
- Is used to represent a collection of related properties
- Doesn't need to know all the keys at compile time
- Most important: is a reference data type
And compared to Structs, we have:
- Values can be of different types in terms of keys and values
- Keys does not support indexing
- You need to know all the different fields at compile time.
- Is used to represent a "thing" with a lot of different properties.