Lesson 7 of 60 · Go
Structs, Methods, and Interfaces
Duration: 25 minutes
Structs
This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.
Structs group related fields.
type Person struct {
Name string
Age int
}
p := Person{Name: "Bob", Age: 30}
Methods (receiver functions)
func (p Person) Greet() string {
return "Hello, " + p.Name
}
func (p *Person) HaveBirthday() {
p.Age++ // pointer receiver mutates the struct
}
Interfaces (behavioral contracts)
type Greeter interface {
Greet() string
}
func Say(g Greeter) {
fmt.Println(g.Greet())
}
Say(p) // Person implements Greeter
Interfaces are satisfied implicitly – no implements keyword.