Slices and ownership
You copy a slice header, change one element through the copy and see the original change. Why? Both headers can refer to the same backing array. Copy elements into independent storage before modifying them when the caller owns the original. Test the original after changing the result. Appending can allocate new storage, so a test must not accidentally depend on capacity.
Missing keys and zero values
A warehouse map contains "dock": 0. How do you distinguish that recorded zero from a missing key? Use value, ok := counts[key]. A missing key returns the value type’s zero and false. A nil map can be read, but writing into it panics. Concurrent access that includes writes needs coordination.
Interfaces and typed nil values
var p *Runner
var w Worker = p
w can be nonnil because it carries the dynamic type *Runner, even though its dynamic value is nil. A nil-safe method may handle that value. An arbitrary method can still panic when it dereferences the receiver. State the interface contract before claiming a nil check makes the call safe.
Errors and generic constraints
When should you use %w? Use it when callers need the wrapped cause, then inspect it with errors.Is or errors.As. A matching error message alone does not establish identity. For a maximum function constrained to ~int | ~int64, initialize the candidate from an input element, so an all-negative slice works. Define an explicit empty-input result.
Goroutines, channels and cancellation
Receiving zero does not prove that a channel is closed. Use comma-ok or range. A nil channel blocks; a closed channel drains buffered values before receives produce zero with ok == false. A cancellation-aware worker needs a stopping path both while receiving input and while sending output. Waiting for goroutines does not protect a shared map or make an increment atomic.
A context checked at entry can become canceled later. Pass it into operations and test cancellation after work starts. In the browser, these tests teach the control flow. Run native race-detector and integration tests before making claims about production concurrency.
HTTP handlers and cleanup
Use httptest.NewRequest and httptest.NewRecorder to test a handler without listening on a socket. Check the status, header and body. A first body write implicitly commits a 200 response if no status was written. Register defer after a resource is acquired successfully so every later return releases it.
Practice these contracts in the Go Interview Hub or take the Go skills assessment. Review the course, exercises and cheat sheet for targeted practice.