Working with JSON in Go

Turn Go structs into JSON and back, control field names with struct tags, process JSON streams, reject unknown fields, and see what JSON v2 in Go 1.27 changes.

Interfaces

Define small interfaces that types satisfy implicitly, use fmt.Stringer, error, io.Reader and io.Writer, and unpack values with type switches.

If and switch in Go

Make decisions in Go with if, else and switch, including the short statement before a condition and why cases don’t fall through.

Building an HTTP server in Go

Write handlers, route requests with method and wildcard patterns, send and receive JSON, set timeouts, shut down gracefully and test it all with httptest.

Go generics

Write one function or type that works with many types: type parameters, constraints, a generic Stack, Go 1.27 generic methods, and when not to use generics.

Functions in Go

Write your own Go functions: parameters, multiple return values, variadic arguments, function values and closures.

Reading and writing files in Go

Read and write whole files, go through a file line by line, append to logs, build portable paths, list directories and embed files in your binary.

Error handling in Go

Create, return, wrap and inspect errors in Go, from if err != nil to errors.Is, errors.As and errors.Join, and when to panic instead.

Context

Cancel goroutines and put time limits on work with context.Context, and follow the conventions every Go API uses.

Constants

Declare constants with const, understand typed and untyped constants, and use iota to build enumerations.