courses / go / level 2

level 2 · medium

intermediate
go.

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.

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

unit 1

Maps

Look things up by name instead of by number.

4 lessons · 36 min

  1. Making a map8 minStore values under names and look any of them up in one step.
  2. Changing a map9 minAdd, change and remove keys, and see what a missing key gives back.
  3. Is it really there?9 minTell a key that is missing apart from a key that holds zero.
  4. 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.

4 lessons · 38 min

  1. Methods9 minGive your own struct its own commands, called with a dot.
  2. Pointers10 minHand over the box itself, so a function can change what is inside.
  3. Pointer receivers9 minWrite methods that change the struct they belong to.
  4. 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.

4 lessons · 38 min

  1. Interfaces10 minWrite one function that works with many different types.
  2. The Stringer8 minDecide how your own types look when they are printed.
  3. Writers10 minSend text to the screen, into a string or anywhere else with one function.
  4. Errors are values10 minSpot a failure the moment it happens, without crashing.

unit 4

Handle what goes wrong

Plan for problems instead of crashing.

4 lessons · 38 min

  1. Making your own errors9 minTurn bad input into a clear message the rest of your program can handle.
  2. Wrapping errors10 minAdd detail to an error without losing what caused it.
  3. Your own error types10 minCarry extra details inside an error and get them back out.
  4. defer9 minMake sure the tidying up happens, however a function ends.

unit 5

The toolbox

Use the ready-made tools that come with Go.

4 lessons · 38 min

  1. Strings in depth9 minSplit, join and search text to pick real data apart.
  2. Formatting verbs9 minLine up tables and show money with exactly two decimal places.
  3. Sorting your own way10 minSort numbers, names and whole structs by any rule you choose.
  4. 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.

4 lessons · 39 min

  1. Files9 minSave text into a file and read it back again.
  2. Reading line by line10 minWork through a file, or typed input, one line at a time.
  3. JSON out10 minTurn your structs into JSON, the text that programs share.
  4. JSON in10 minRead JSON text back into your own structs, and catch bad data.

unit 7

The web

Answer web requests like a real server.

4 lessons · 44 min

  1. Handlers10 minWrite the code that answers a web request, and test it without a network.
  2. Routes and status codes11 minSend each request to the right answer, and say how it went.
  3. A JSON API12 minRead JSON requests and send JSON replies, like a real web service.
  4. panic and recover11 minStop one bad request from bringing the whole server down.
end of level 2 level check: a tuck shop JSON API Build one small project with everything from this level. Pass it and your face levels up. see the check

next, level 3

advanced
go.

Write concurrent Go like a professional: goroutines, channels, context, tests, benchmarks and clean design.

see level 3