In-Class Go Exercise 4

Exercise · Explain This Go Struct (User Profile)

Go · Beginner+
Explain this Go code out loud like you're introducing a data model during a backend developer interview. Focus on the struct, fields, data types, and object creation.
package main

import "fmt"

type User struct {
	ID    int
	Name  string
	Email string
}

func main() {

	user := User{
		ID:    1,
		Name:  "Robbie",
		Email: "robbie@example.com",
	}

	fmt.Println(user)

}
🎯 Instructions oral task
  1. Explain what a struct is.
  2. Describe each field in the User struct.
  3. Explain the data type of each field.
  4. Describe how a User object is created.
  5. Explain what values are assigned.
  6. Describe what gets printed to the console.
  7. Explain why structs are useful in Go applications.
📖 Vocabulary core
  • struct — custom data type that groups related fields together.
  • field — individual piece of data inside a struct.
  • data type — defines what kind of value can be stored.
  • instance — created object based on a struct.
  • attribute — characteristic or property of an object.
  • model — representation of real-world data.
  • initialize — assign initial values when creating an object.
🧩 Collocations natural English
  • define a struct
  • store user information
  • create an instance
  • assign values to fields
  • represent business data
  • print an object
🗣️ Phrasal Verbs interview speech
  • set up — “We set up a struct to hold user data.”
  • fill in — “We fill in the fields with values.”
  • store away — “The application stores away user information.”
  • print out — “The program prints out the struct contents.”
💬 Useful Interview Phrases communication
  • “This struct represents...”
  • “The purpose of this model is to store...”
  • “Each field contains...”
  • “An instance of the struct is created...”
  • “The values are initialized using...”
  • “This approach makes the code more organized and maintainable.”
🎤 Model Answer spoken

This code defines a struct called User. A struct is a custom data type in Go that allows us to group related pieces of information together.

The User struct contains three fields. The first field is ID, which is an integer. The second field is Name, which is a string. The third field is Email, which is also a string.

Inside the main function, we create an instance of the User struct. We assign the value 1 to the ID field, "Robbie" to the Name field, and "robbie@example.com" to the Email field.

After creating the object, the program prints the struct to the console using fmt.Println(). The output contains all of the field values stored inside the User object.

Structs are commonly used in backend applications because they help organize and represent business data such as users, products, orders, or API responses.