Mini CLI: unit converter
Build a command-line tool that converts Celsius to Fahrenheit and vice versa. Keep the full solution under 60 lines, validate bad input, and print helpful usage text.
Languages / Knowledge library
compiled language for concurrent networked software
Go helps teams ship fast, reliable backend and infrastructure software with simple syntax, built-in concurrency (goroutines/channels), strong standard tooling, and easy static-binary deployment.
Designed at Google by Robert Griesemer, Rob Pike, and Ken Thompson (work started in 2007). Publicly announced in 2009 and open-sourced soon after. Go 1.0 released in 2012 with a strong compatibility promise. Go modules became the default dependency system in Go 1.16.
Work through these exercises in order. Try the task before opening a reference.
Build a command-line tool that converts Celsius to Fahrenheit and vice versa. Keep the full solution under 60 lines, validate bad input, and print helpful usage text.
Create an HTTP server with `/health` returning JSON: `{ "status": "ok" }`. Add proper status code, content-type header, and one unit test for the handler.
Implement a 3-stage pipeline (generate -> transform -> aggregate) using goroutines and channels. Add `context.Context` cancellation and ensure no goroutine leaks.
Create a Go module that wraps a public REST API. Include retries with backoff, context-aware timeouts, and table-driven tests for success/error paths.
Take a CPU-heavy function, profile it with `pprof`, optimize one hotspot, then run with PGO and compare benchmark results before/after.
Industrial manufacturing firms managing thousands of remote sensors.
High-latency data ingestion bottlenecks caused by synchronous processing of incoming sensor telemetry streams.
Utilizing Go's built-in concurrency primitives, specifically goroutines and channels, to decouple network ingestion from data processing, allowing the system to handle thousands of concurrent connections without blocking.
Flow of data from sensors through concurrent handlers to storage.
External IoT device
Entry point for requests
Concurrent request handler
Thread-safe data pipe
Background persistence
This code demonstrates the asynchronous pattern where the HTTP handler spawns a goroutine to process data, allowing the main thread to return a response to the sensor immediately, preventing ingestion bottlenecks.
func handleSensor(w http.ResponseWriter, r *http.Request) {
go func() { // Spawn goroutine for non-blocking processing
data := parse(r) // Parse incoming telemetry
dataChan <- data // Send to background worker via channel
}()
w.WriteHeader(http.StatusAccepted) // Return immediately to sensor
}Improved system responsiveness and the ability to scale ingestion capacity linearly with available CPU resources.
Goroutines are lightweight but not infinite; excessive spawning without a worker pool can lead to memory exhaustion, which is monitored by checking the runtime memory statistics.