Errors, goroutines and a complete program

Handling problems with errors, running work at the same time with goroutines and channels, and building a small command-line program.

About 4 hours of study

Learning objectives

Lessons

  1. 1

    Errors, panic and recover Intermediate

    Go's way of handling problems: error values returned from functions, errors.New and fmt.Errorf, wrapping with %w, errors.Is and errors.As, custom error types, and panic with recover.

  2. 2

    Goroutines and channels Intermediate

    Running work at the same time with goroutines, passing values with channels, buffered channels, closing and ranging over a channel, waiting with sync.WaitGroup, protecting data with sync.Mutex and choosing with select.

  3. 3

    Putting it together: a command-line program Intermediate

    Designing and writing a small complete Go program from commands read on the input, using structs, methods, maps, slices, errors and a command loop.

Module practice

Module quiz

1. How does a normal Go function report a failure?
2. Which verb wraps an error inside another one in fmt.Errorf?
3. Which keyword starts a goroutine?
4. Who should close a channel?
5. What does sync.WaitGroup do?
6. Where must recover be called to stop a panic?

‹ Structs, methods and interfacesFinal assessment ›