Learn Go by writing it. Every topic here is a small runnable program, and each chapter ends with notes in my own words — the bits I want to remember when I come back to the code.
Each NN-slug/ is a self-contained module that can be read on its own.
Status: a beginner guide covering core Go topics through generics (environment, predeclared types, composite types, blocks/control, functions, pointers, types & methods, interfaces, errors, generics). Advanced topics are not covered yet — add them as new chapters following the same layout. Fixes and typos are welcome; see "Contributing" below.
You are new to Go, or new to a statically typed, compiled language, and want to learn by running small programs instead of reading a textbook cover to cover. You should already be comfortable with at least one programming language (loops, functions, basic types). No prior Go knowledge is assumed.
- Go 1.27 or newer (
go version). Install from https://go.dev/dl/. make(any POSIX make; on Debian/Ubuntu:sudo apt install make).git(to clone and to switch chapters).- A terminal and any text editor. GoLand/VS Code are optional, not required.
git clone https://github.com/0xengr/just-go.git
cd just-go
make list # every chapter and every topic inside it
make check # gofmt + vet + build across all chapters
make -C 01-hello-go run 01-greet Ada # run one topic, with the bannerThen open 01-hello-go/README.md: it opens with the big idea, a run-order
table, and one section per topic with the code and its real output.
Each chapter is a self-contained Go module:
NN-slug/
├── go.mod module path for this chapter
├── main.go orientation stub (overview only)
├── Makefile same in every chapter, auto-discovers examples
├── README.md index: big idea, run order, exercises pointer
├── notes.md full chapter notes
├── examples/ runnable package main folders
│ └── 01-topic/
│ └── main.go
└── exercises/ practice tasks (code only)
└── 01-slug/
└── main.go
- Topics are numbered folders (
01-,02-, …) in reading order, solsalone tells a newcomer where to begin. The numbers are the curriculum, not a version. - Every topic is its own
package main: run it withgo run ./examples/01-topicormake -C NN-slug run 01-topic. - The chapter
README.mdis the index; the full notes live innotes.md. - Exercises live under
exercises/; the chapterREADME.mdlists each one with the topics it solves.
make -C 03-composite-types run 02-slices # with animated banner
make -C 03-composite-types run 02-slices ANIM=0 # skip the banner
make -C 01-hello-go run exercises/01-name-badge # run an exercise
make -C 03-composite-types list # list topics
make -C 03-composite-types check # gofmt + vet + build
make -C 03-composite-types new my-topic # scaffold a new topicAt the repo root, make list shows every chapter's topics and make check
runs the gate across all of them; make -C <chapter> <target> works too.
Reference notes: fmt-printing.md — all 12 fmt print functions + verbs.
67 runnable topics across 10 chapters. Start here runs the first topic in
reading order; the chapter README.md has the full run-order table.
| Dir | Chapter | Topics | Start here | You'll learn |
|---|---|---|---|---|
01-hello-go/ |
Go environment & toolchain | 2 | make -C 01-hello-go run 01-greet Ada |
modules, go run/build/fmt/vet |
02-predeclared-types/ |
Predeclared types & declarations | 6 | make -C 02-predeclared-types run 01-zero-values |
zero values, var/:=, const, numerics, strings, conversions |
03-composite-types/ |
Arrays, slices, maps & structs | 11 | make -C 03-composite-types run 01-arrays |
arrays, slices, maps, structs, strings/bytes |
04-blocks-shadows-control/ |
Blocks, shadows & control structures | 9 | make -C 04-blocks-shadows-control run 01-blocks |
scope, shadowing, if/for/switch/goto |
05-functions/ |
Functions, closures & defer |
5 | make -C 05-functions run 01-multiple-returns |
multiple returns, variadic, closures, defer |
06-pointers/ |
Pointers, nil, new() & call by value |
6 | make -C 06-pointers run 01-call-by-value |
pointers, mutability, map/slice diffs, perf |
07-types-and-methods/ |
Types and methods (types + methods) | 4 | make -C 07-types-and-methods run 01-user-defined-types |
defined types, methods, receivers, embedding |
08-interfaces/ |
Interfaces: duck typing, APIs & type switches | 4 | make -C 08-interfaces run 01-duck-typing |
interfaces, implicit satisfaction, polymorphism, API design, type switches |
09-errors/ |
Errors: values, wrapping, panic & recover | 10 | make -C 09-errors run 01-error-kinds |
error values, error kinds, sentinels, wrapping, errors.Is/errors.As, panic, defer, recover |
10-generics/ |
Generics: type parameters & constraints | 10 | make -C 10-generics run 01-type-constraints |
type parameters, generic types, generic functions, constraints, type inference, type terms, interface constraints, comparable, stdlib generics |
Each chapter is its own Go module (go.mod naming github.com/0xengr/just-go/<slug>)
with its own overview main.go and README.md; there is no root module and no
go.work. Chapter 1 is the exception: its overview main.go is a runnable hello
world, the rest are orientation stubs.
Topic folders are numbered in reading order (01-, 02-, …) within each
chapter, so ls on any chapter shows a newcomer where to begin. The numbers are
the curriculum, not a version.
These topics are not in the repo yet; add them as new chapters (11-...,
12-..., …) following the existing layout:
- Advanced errors (
errors.Join, multi-error handling) - Modules, packages, imports
- Go tooling (goimports, linters, build tags, embed)
- Concurrency (goroutines, channels, select)
- Standard library (io, time, json, http)
- Context
- Writing tests
- reflect, unsafe, cgo
Every chapter has the same Makefile; it finds the chapter name and its topics
by itself, so there is nothing to configure.
| Command | What it does |
|---|---|
make / make help |
list the targets |
make list |
list this chapter's topics |
make run [topic] [args] |
run ./main.go (overview) if no topic, else a topic under examples/, exercises/, or a nested path (ANIM=0 to skip) |
make new <topic> |
scaffold <topic>/main.go |
make test |
go test ./... |
make check |
gofmt + vet + build for the chapter |
Run them from a chapter folder, e.g. cd 05-functions && make run 01-multiple-returns.
At the repo root, make list shows every chapter's topics and make check runs
the gate across all of them; make -C <chapter> <target> works too. Root-only
targets: make run <chapter> [topic] [args] (runs an overview or a topic) and
make new-chapter <name> (alias make new <name>) to scaffold a new chapter.
Add ANIM=0 to skip the banner, e.g. make run 01-greet Ada ANIM=0.
Reference notes: fmt-printing.md — all 12 fmt print functions + verbs.
- Small language, few ways to do things: easy to read other people's code.
- Fast static binaries with no runtime to install: great for CLIs and services.
- Built-in concurrency (
goroutines+channels) without extra libraries. - Strong stdlib (HTTP, JSON, testing, tooling) so projects stay lean.
- Backward-compatibility promise: old code keeps building on new toolchains.
- Static typing with inference (
:=), garbage collected, compiles to one binary. - Explicit error returns instead of exceptions;
deferfor cleanup. - Interfaces are satisfied implicitly (no
implementskeyword). struct+ embedding for composition instead of inheritance.- Generics (since 1.18) for type-safe containers/algorithms without
anysprawl. - Cross-compilation via
GOOS/GOARCHenv vars.
| Command | What it does | Example |
|---|---|---|
go run . / go run ./<dir> |
Compile to temp dir and run | go run ., go run ./01-greet |
go build ./... |
Compile all packages, check for errors | go build ./... |
go vet ./... |
Static checks (printf verbs, dead code, etc.) | go vet ./... |
gofmt -l . |
List files needing format (empty = clean) | gofmt -l ., gofmt -w . |
go mod init <path> |
Start a new module | go mod init example.com/demo |
go mod tidy |
Add missing / drop unused deps | go mod tidy |
go get <pkg>@<ver> |
Add or bump a dependency | go get github.com/foo/bar@v1.2.3 |
go test ./... |
Run tests in all packages | go test ./... |
go test -run TestName ./... |
Run one focused test | go test -run TestGreet . |
go env GOVERSION GOOS GOARCH |
Show toolchain / target platform | go env GOVERSION |
go version |
Installed toolchain version | go version |
Per-chapter check: gofmt -l . && go vet ./... && go build ./....
- "go: cannot find main module" — you ran
go runfrom the repo root.cdinto a chapter folder first (cd 03-composite-types), thengo run ./02-slices. Or usemake -C 03-composite-types run 02-slicesfrom anywhere. - "unknown topic" — topic names are the folder names including the number
(
02-slices, notslices). Exercises can be run asexercises/01-...(or by their bare name when unambiguous), and nested paths are supported too. gofmt -l .lists files — rungofmt -w .(ormake fmt) and re-check.go vetcomplains about printf verbs — fix the format string; vet is right more often than you are.- Module path mismatch after cloning/forking — the module path is
github.com/0xengr/just-go/<slug>. If you fork under your own account, do a find-and-replace acrossgo.modfiles (and update imports) or keep the original path and build locally.
See GLOSSARY.md for plain-English definitions of the Go
terms used across the chapters.
- A Tour of Go — interactive intro.
- Effective Go — idioms.
- Go by Example — short runnable snippets.
- Go standard library docs.
This repo is a beginner guide covering core Go topics through errors. Contributions
that fix typos, correct facts or output, improve notes, or add the missing
chapters (10–18) following the existing layout are welcome. Please keep each
chapter a self-contained module with the shared Makefile, run make check
before submitting, and open a PR rather than pushing to main.
MIT — see LICENSE.