1 min read 116 words Updated Sep 24, 2026 Created Sep 24, 2026
#Go#Programming

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}

Struct embeddings

When embedding a struct in a anonymus way, the fields of it are "promoted", similar to destructuring in TypeScript/JavaScript

Next chapter: Maps