Build useful Go programs with maps, methods, interfaces, errors, files, JSON and web handlers.
- 28 lessons
- 7 units
- 4 h 31 m in all
- £0, for good
what’s inside.
For people who finished Level 1, or can already write small programs with variables, decisions, loops and functions.
Twenty-eight lessons take you from maps and methods to interfaces, careful error handling and Go's standard library. You save data in files, speak JSON and write web handlers that you test without a network. You finish by building a tuck shop JSON API that takes orders, tracks stock and answers every request properly.
every lesson goes the same way.
- meet it
- guess first
- your turn
- fix it
- nailed it
unit 1
Maps
Look things up by name instead of by number.
- Making a map8 minStore values under names and look any of them up in one step.
- Changing a map9 minAdd, change and remove keys, and see what a missing key gives back.
- Is it really there?9 minTell a key that is missing apart from a key that holds zero.
- Counting and walking a map10 minKeep a tally, then visit every key in a steady order.
unit 2
Methods and pointers
Give your own types their own commands.
- Methods9 minGive your own struct its own commands, called with a dot.
- Pointers10 minHand over the box itself, so a function can change what is inside.
- Pointer receivers9 minWrite methods that change the struct they belong to.
- nil and constructors10 minBuild structs safely and spot a pointer that points at nothing.
unit 3
Interfaces
Write code that works with many different types.
- Interfaces10 minWrite one function that works with many different types.
- The Stringer8 minDecide how your own types look when they are printed.
- Writers10 minSend text to the screen, into a string or anywhere else with one function.
- Errors are values10 minSpot a failure the moment it happens, without crashing.
unit 4
Handle what goes wrong
Plan for problems instead of crashing.
- Making your own errors9 minTurn bad input into a clear message the rest of your program can handle.
- Wrapping errors10 minAdd detail to an error without losing what caused it.
- Your own error types10 minCarry extra details inside an error and get them back out.
- defer9 minMake sure the tidying up happens, however a function ends.
unit 5
The toolbox
Use the ready-made tools that come with Go.
- Strings in depth9 minSplit, join and search text to pick real data apart.
- Formatting verbs9 minLine up tables and show money with exactly two decimal places.
- Sorting your own way10 minSort numbers, names and whole structs by any rule you choose.
- Dates and times10 minBuild fixed dates, format them nicely and count the days between.
unit 6
Files and JSON
Save your data and share it with other programs.
unit 7
The web
Answer web requests like a real server.
- Handlers10 minWrite the code that answers a web request, and test it without a network.
- Routes and status codes11 minSend each request to the right answer, and say how it went.
- A JSON API12 minRead JSON requests and send JSON replies, like a real web service.
- panic and recover11 minStop one bad request from bringing the whole server down.