The struct type

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 ...

Get Learning Go Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.