Learn Go – tutorial, cheatsheet & exercises
Go (also called "Golang") was developed at Google in 2009 with the goal of making software for large teams and servers simple, fast and reliable. The language has only a few keywords, no class inheritance and no exceptions. In return, it compiles in seconds to a single, fast binary with no dependencies.
Go shines in cloud services, web APIs, command-line tools and infrastructure: Docker, Kubernetes and Terraform are written in Go. Built-in concurrency (goroutines and channels), a large standard library and the unified go tool make getting started easy. This course uses current Go (1.22 or newer).
Hello World in Go
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}Every executable program needs package main and a main function; fmt.Println prints a line. Start it with go run ..
How to get started with Go
Install Go from go.dev/dl – on the Mac with brew install go, on Windows with winget install GoLang.Go. Check the installation in the terminal:
go versionEvery project is a module. Create a folder and initialize it with go mod init – the name is usually a repository path, and for exercises something like example.com/hallo is enough:
mkdir hallo
cd hallo
go mod init example.com/halloCreate a file main.go containing a Hello World program and run it:
package main
import "fmt"
func main() {
fmt.Println("Hello World!")
}go run . # compile and run
go build -o hallo # produce a binary
./hallogopls) or GoLand. go fmt ./... formats your code uniformly – in Go there are no style debates, gofmt takes care of that.Go learning path
Hello World & Program Structure
Package, import, the main function and formatted output.
Variables, Types & Constants
var, :=, zero values, type conversion and const.
Conditions: if and switch
Making decisions – without parentheses and without a ternary operator.
Loops: for only
Go has exactly one loop construct – with many forms.
Functions
Multiple return values, variadic parameters and closures.
Arrays, Slices & Maps
The core collection types and their pitfalls.
Structs, Methods & Pointers
The Go way to "objects": data in structs, behavior in methods.
Interfaces
Implicit contracts, type assertions and the empty interface type.
Errors as Values
error returns, wrapping with %w, and errors.Is and errors.As.
defer, panic & recover
Guarantee cleanup and catch exceptional situations.
Files & JSON
Read and write text, exchange data as JSON.
At a glance
More about Go
Test & practice
Interactive quiz, timed exam with certificate, and exercises with an editor: