Structs
A struct groups related fields into one type.
Think of it as a form with labeled boxes.
One form can hold a name, an age, and a city together.
Use structs for people, products, settings, or any named pieces of data.
Defining a struct
Declare a type with type Name struct { ... }.
Each field has a name and a type.
Exported fields start with a capital letter so other packages can see them.
Creating values
Create values with field names for clarity.
You can also list values in order if you fill every field.
Named fields are easier to read.
Updating fields
Access fields with a dot.
Put a new value in a field the same way.
Pointers to structs
With a pointer to a struct, you can still write p.Name.
Go follows the pointer for you.
That makes updates easy without writing (*p).Name every time.
Embedding
You can put one struct inside another.
Its fields can show up on the outer type.
That is called embedding. It feels like stacking forms.
Capitalize field names you want other packages to see.
Test yourself
Three quick questions made just for this lesson. Earn 10 XP per correct answer.