Thuta Learning
Go
BasicProgrammingBeginner

Go HOME

GoLesson 115 min

What you'll walk away with

  • Describe what kind of language Go is (compiled, statically typed, garbage-collected, with built-in concurrency) and where it is used
  • Name the five chapters (Basic, Intermediate, Advanced, Projects, Exercises) and what each one covers
  • Recognize the three parts of every runnable file in this course: package main, imports and func main
  • Run a single file with go run and compare the result with the output you predicted

Explain it simply

Go in plain words

Go (also called Golang) is a programming language designed at Google by Robert Griesemer, Rob Pike and Ken Thompson and released as open source in 2009. The Go compiler turns your `.go` files into machine code the computer runs directly, so programs start quickly and run fast.

Go's signature trait is simplicity. It has few keywords and usually only one or two ways to write something, which makes code written by other people easy to read. That is why it is so popular for API servers, command-line tools, cloud services and DevOps tools.

Problem → Why → Solution

The problem: copying advanced code before the basics

Many beginners have heard about goroutines, so they copy some concurrency code from the internet and run it straight away. The program below starts a goroutine that should print one line. There is no error, yet when you run it, usually nothing is printed at all.

If you do not yet know what a function is, what a goroutine is or when a program ends, you cannot explain why this code prints nothing. You end up lost searching for answers and decide Go must be hard.

main.go
package main

import "fmt"

func main() {
    go fmt.Println("hello from a goroutine")
    // main returns here, and the whole program exits with it,
    // usually before the goroutine has had a chance to print.
}

Why the order of lessons matters

Go's features are built on top of each other. Goroutines need functions, channels need types, and error handling rests on interfaces. This course is ordered the same way, so each lesson uses the ones before it. By the time you reach the Goroutines lesson in the Advanced chapter, you will be able to fix the program above yourself.

Core concept: what Go is and how this course is laid out

You can remember Go by four properties. First, it is compiled: code is turned into machine code before it runs, producing a single executable file. Second, it is statically typed: every variable has a type, and the compiler catches type mismatches before the program runs.

Third, it has a garbage collector, so you never free memory by hand. Fourth, its concurrency features, goroutines and channels, are part of the language itself, which makes it easy to write servers that do many things at once. On top of that, a single `go` command bundles the tools to run, build, test, format and vet your code.

This course splits its 32 lessons into five chapters, and each chapter lays the foundation the next one needs.

ChapterWhat you learn
Basic (6 lessons)What Go is, setup, syntax, variables and data types
Intermediate (8 lessons)Functions, arrays, slices, maps, loops, structs, methods, interfaces
Advanced (13 lessons)Generics, pointers, errors, modules, goroutines, channels, context, HTTP, testing and a mini project
Projects (3 lessons)Build a Task Manager in three parts, from structs and slices to JSON auto-save
Exercises (2 lessons)A core basics review and an interfaces and concurrency challenge

Every lesson follows the same shape: a plain explanation, a problem, the core concept, an example with a line-by-line breakdown, common mistakes, a mini challenge and three quiz questions. Each example is one file with `package main` and `func main()`, so you can run it directly with `go run main.go`.

Go takes backward compatibility seriously. Under the Go 1 compatibility promise, programs written correctly for Go 1 are meant to keep compiling with newer Go 1.x releases, so the fundamentals you learn here will stay useful for years. When a feature needs a particular release, the lesson says so explicitly, for example 'Go 1.22 and later'.

Mental model: how to study each lesson
  1. Read the explanation
  2. Predict the output
  3. Run it with go run
  4. Change one thing, run again

Whenever your prediction and the real output differ, you have found exactly what to learn next.

General pattern: a runnable Go file

main.go
package main

import "fmt"

func main() {
    name := value
    fmt.Println(name)
}

`package main` says this file is a runnable program. `import` brings in the packages you use, and the statements inside `func main()` run in order from top to bottom. Every example in this course follows this skeleton.

Your first Go program: a course progress report

The program below stores some course facts in variables and works out how many lessons are left. Save it as `main.go` and run it with `go run main.go`. Predict the four lines before you run it, paying attention to the spaces `Println` puts between its items.

main.go
package main

import "fmt"

func main() {
    course := "Go"
    totalLessons := 32
    chapters := 5
    finished := 1

    fmt.Println("Welcome to the", course, "course!")
    fmt.Printf("%d lessons in %d chapters\n", totalLessons, chapters)
    fmt.Println("Lessons left:", totalLessons-finished)
    fmt.Println("Next lesson: What is Go?")
}

Code breakdown

  1. An executable programpackage main

    Every Go file starts with a package clause. The name `main` tells the compiler this is a runnable program, not a library.

  2. Values with inferred typestotalLessons := 32

    `:=` declares a new variable and gives it a value. From `32` the compiler infers the type `int`. The Variables lesson covers this in depth.

  3. Println adds spacesfmt.Println("Welcome to the", course, "course!")

    `Println` puts one space between its arguments and a newline at the end, which is why the words come out as `Welcome to the Go course!` and not glued together.

  4. Formatted outputfmt.Printf("%d lessons in %d chapters\n", totalLessons, chapters)

    `Printf` fills each `%d` in the format string with the next integer. Unlike `Println` it does not add a newline for you, so the `\n` is written by hand.

  5. Arithmetic inside a callfmt.Println("Lessons left:", totalLessons-finished)

    `totalLessons-finished` is evaluated first, giving `31`, and then printed. Go will not join a string and a number with `+`, so they are passed as separate arguments.

You should see
Welcome to the Go course!
32 lessons in 5 chapters
Lessons left: 31
Next lesson: What is Go?
From main.go to output
  1. Save main.go
  2. go run compiles it
  3. The program runs main()
  4. Four lines are printed

Code compiles

A temporary executable runs and prints the report

Compile error

file:line:column plus a message; nothing runs

In real projects

Where Go is used in the real world

A large share of cloud infrastructure is written in Go. Docker, Kubernetes, Terraform, Prometheus, etcd and the static site generator Hugo are all Go projects. These tools chose Go because it produces a single executable you copy to a server and run, because goroutines let one process handle thousands of network requests at once, and because it compiles fast.

Companies use Go for backend APIs, microservices, data pipelines and the internal command-line tools their teams rely on. The projects in this course are small versions of that work: the Task Manager project is a CLI tool that saves its data to a JSON file, and the HTTP & JSON API lesson shows the basics of a backend service. By the end you will be able to write small tools like these yourself.

Common mistakes

Common mistakes when starting out

1. Reading code without running it

An example can feel obvious when you only read it. Running it yourself is how you notice details such as the spaces `Println` adds or a forgotten `\n` in `Printf`. Copy and run every example, then change one value and run it again.

2. Skipping over the compile error message

A message like `./main.go:9:5: declared and not used: name` gives you the file, line 9, column 5 and the exact problem. Go's compiler messages are short and precise, so jump straight to that line instead of guessing and changing code all over the file.

3. Jumping ahead to the advanced topics

Goroutines and channels are Go's big attraction, but without functions, slices, structs and interfaces you cannot explain what goes wrong when a problem appears. Finish the Basic and Intermediate chapters first; the later lessons assume you know them.

Best practices

Good study habits

  • Keep a separate folder per lesson and experiment in a single `main.go` file.
  • Try each mini challenge on your own before opening the solution, and open the hint only if you need it.
  • When you miss a quiz question, read its explanation and rerun the example.

Mini challenge

Mini challenge: print your study plan

Decide how many lessons you will study per week and write a program that prints your plan for this course.

  • Store your name, the total lessons (32) and lessons per week (4) in variables with `:=`
  • Work out how many lessons remain after the Basic chapter (6 lessons)
  • Work out how many weeks the whole course will take
  • Use both `Println` and `Printf` at least once
main.go
package main

import "fmt"

func main() {
    // TODO: learner name, total lessons, lessons per week
    // TODO: the Basic chapter has 6 lessons

    // TODO: print the learner's name with Println
    // TODO: print lessons left after Basic
    // TODO: print the number of weeks with Printf and %d
}

Expected: Learner: Aye Aye Left after Basic: 26 Weeks to finish: 8

Show hint

Dividing two integers with `/` in Go drops the fraction and gives an integer. 32 / 4 is exactly 8, so that is fine for this challenge.

Show solution
main.go
package main

import "fmt"

func main() {
    learner := "Aye Aye"
    total := 32
    perWeek := 4
    basic := 6

    fmt.Println("Learner:", learner)
    fmt.Println("Left after Basic:", total-basic)
    fmt.Printf("Weeks to finish: %d\n", total/perWeek)
}

Quick quiz 1 / 3

Where does a Go program start running?

Quick quiz 2 / 3

With total := 32 and done := 1, what does fmt.Println("Lessons left:", total-done) print?

Quick quiz 3 / 3

In this course, which chapter teaches goroutines and channels?

What to remember

  • Go is compiled, statically typed and garbage-collected, with goroutines and channels built into the language.
  • This course orders its 32 lessons into five chapters: Basic, Intermediate, Advanced, Projects and Exercises.
  • Every runnable file has package main, imports and func main(), and runs with go run main.go.
  • Predict each example's output, run it, then change one thing and run it again.

Go release history — Go

Updated on

Progress is saved only in this browser on this device. It isn't synced to other devices.

Report a problem with this lessonOpens your email app with this lesson's address filled in — nothing is sent until you send it.

Go HOME | Thuta Learning