AdvancedProduction Go
Lab: production Go
Apply net/http, JSON handling, profiling, and build decisions to realistic scenarios.
Lab · optionalGoAdvanced10 min
Recommended first
By the end of this lesson you will be able to:
- Structure an HTTP handler correctly using the standard library
- Spot JSON encoding and decoding pitfalls
- Interpret a pprof profile to locate a bottleneck
- Choose between static binary, Docker image, and CGO for deployment
Optional scenario lab. Production Go is a series of small decisions: how to register routes, what a JSON mismatch looks like, where to look first in a profile. Practice them here.
Scenarios: production Go
- 1.You register a handler with
http.HandleFunc("/users", handleUsers). A request arrives at/users/42. What does the defaultServeMuxdo? - 2.A struct field is declared as
Name string(no json tag). What key appears in the JSON output ofjson.Marshal? - 3.A Go CPU profile showing one function consuming 80% of the samples is a reliable signal to optimise that function first.
- 4.You need the smallest, most portable Linux binary — no shared library dependencies. Which build setting achieves this?
- 5.You want to log every request's method, path, and duration without touching each individual handler. The right approach in net/http is:
The production-Go mindset: know your ServeMux's matching rules, keep your JSON tags explicit, profile before you optimise, and build statically by default.
Finished reading? Mark it complete to track your progress.