Skip to content

Posts

Go Basics: Parse CLI Options Without Exiting the Process

Use a dedicated flag.FlagSet with ContinueOnError and validate values after parsing.

Read more →

October 31, 2026

Go Basics: Finish a Channel Stream Without Sentinel Values

Let a producer close its channel and consume buffered values with range.

Read more →

October 31, 2026

Go Basics: Exercise an HTTP Handler Without Opening a Port

Use httptest.NewRequest and ResponseRecorder to check method handling, status, headers, and JSON output.

Read more →

October 31, 2026

Go Basics: Escape Untrusted Text in HTML Templates

Render a small HTML fragment with html/template and observe automatic escaping.

Read more →

October 31, 2026

Go Basics: Encode Fixed-Width Records with Explicit Byte Order

Write and read a six-byte binary header using encoding/binary and validate its length.

Read more →

October 31, 2026

Go Basics: Distinguish Missing Map Keys from Zero Values

Use comma-ok lookups and sorted keys to produce a deterministic inventory report.

Read more →

October 31, 2026

Go Basics: Count Concurrent Events with Typed Atomics

Update an atomic.Int64 from multiple goroutines and read the final count after completion.

Read more →

October 31, 2026

Go Basics: Copy Slices Before Editing Shared Data

See how slice views share an array, then use slices.Clone to isolate a working copy.

Read more →

October 31, 2026

Go Basics: Build URL Queries Without String Concatenation

Use net/url values to encode spaces, ampersands, and repeated query parameters.

Read more →

October 31, 2026

Go Basics: Avoid Typed-Nil Error Surprises

Compare a nil error interface with an error interface holding a nil pointer.

Read more →

October 31, 2026