June 2017
Beginner
1091 pages
22h 9m
English
The last type discussed in this chapter is Go's struct. It is a composite type that serves as a container for other named types known as fields. The following code snippet shows several variables declared as structs:
var(
empty struct{}
car struct{make, model string}
currency struct{name, country string; code int}
node struct{
edges []string
weight int
}
person struct{
name string
address struct{
street string
city, state string
postal string
}
}
)
golang.fyi/ch07/structtypes.go
Note that the struct type has the following general format:
struct{<field declaration set>}
The struct type is constructed by specifying the keyword struct followed by a set of field declarations enclosed within curly brackets. In its most common form, a field ...
Read now
Unlock full access