September 2017
Intermediate to advanced
466 pages
9h 33m
English
Although arrays, slices, and maps are all very useful, they cannot hold multiple values in the same place. When you need to group various types of variables and create a new handy type, you can use a structure--the various elements of a structure are called fields.
The code of this subsection is saved as dataStructures.go and can be divided into three parts. The first part contains the preamble and the definition of a new structure named message:
package main
import (
"fmt"
"reflect"
)
func main() {
type message struct {
X int
Y int
Label string
}
The message structure has three fields, named X, Y, and Label. Note that structures are usually defined at the beginning of a program and outside the main() function.
The second part ...
Read now
Unlock full access