A struct is a collection of fields.

type Person struct {
	Name string
	Age  int
}
 
fmt.Println(Person{"Max", 23})

Struct fields can be accessed using a dot: max.Name.

Access through pointers

 
max := Person{"Max", 25}
p := &max
fmt.Println(p.Name)

Overwriting values:

p := &max
p.Age = 26

Struct literals

type Point struct { X int Y int } 
 
// Struct literal with field names 
point := Point{X: 10, Y: 20} 
 
 
// Struct literal without field names (order matters) 
point := Point{10, 20}

Next chapter: Maps