GoGo

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).

Cloud & microservicesCLI toolsDevOps (Docker, Kubernetes)

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 version

Every 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/hallo

Create 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
./hallo
TipUse VS Code with the "Go" extension (which bundles gopls) or GoLand. go fmt ./... formats your code uniformly – in Go there are no style debates, gofmt takes care of that.
WarningThe Go compiler is strict: unused variables and unused imports are errors, not warnings. This keeps the code clean but can be annoying when experimenting.

At a glance

First released2009
CreatorGriesemer, Pike, Thompson (Google)
ParadigmProcedural, concurrent
TypingStatic, strong
ExecutionCompiled to machine code
File extension.go

Test & practice

Interactive quiz, timed exam with certificate, and exercises with an editor:

Go compared

Hello World: Go comparedVariables: Go comparedConditionals: Go comparedLoops: Go comparedFunctions: Go comparedLists and Arrays: Go comparedDictionaries and Maps: Go comparedClasses and Objects: Go comparedError Handling: Go comparedReading Files: Go compared