Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons

© 2026 BraveProgrammer. All rights reserved.

  1. Courses
  2. /
  3. Go Programming Bootcamp

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.

Info

Use a pointer receiver when the method needs to modify the receiver or avoid copying large structs.

Previous: Arrays, Slices, and MapsNext: Error Handling & Defer