golang
# structs
structs are typed collections of fields. They’re useful for grouping data together to form records.
|
|
Instances of the struct can be created in a variety of ways
|
|
Above will create a local Person variable that is by default set to zero. For a struct zero means each of the fields is set to their corresponding zero value (0 for ints, 0.0 for floats, "" for strings, nil for pointers, …)
|
|
Above allocates memory for all the fields, sets each of them to their zero value and returns a pointer *Person
. More often we want to give each of the fields a value. We can do this in two ways. Like this:
|
|
Field names can be left off if you know the order that they are defined
|
|
Structs are mutable
|
|