

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
Not enough gems
Cost: 6 gems
1: Structs in Go
incomplete
2: Nested Structs in Go
incomplete
3: Anonymous Structs in Go
incomplete
4: Embedded Structs
incomplete
5: Struct Methods in Go
incomplete
6: Memory Layout
incomplete
7: Empty Struct
incomplete
8: Empty Struct
incomplete
9: Update Users
incomplete
10: Send Message
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
We use structs in Go to represent structured data. It's often convenient to group different types of variables together. For example, if we want to represent a car we could do the following:
type car struct {
brand string
model string
doors int
mileage int
}
This creates a new struct type called car. All cars have a brand, model, doors and mileage.
To create a car, use a struct literal:
myCar := car{
brand: "Toyota",
model: "Camry",
doors: 4,
mileage: 5000,
}
Structs in Go are often used to represent data that you might use a dictionary or object for in other languages.
Complete the definition of the messageToSend struct. It needs two fields:
phoneNumber - an integermessage - a string.