Code-Memo

Idiomatic Go

Formatting and naming

Errors

Interfaces

Zero values

Design structs so the zero value is usable or obviously invalid — reduces constructor boilerplate when safe.

Line of sight

Handle errors in the happy path down the left margin; reduce deep nesting with early returns.

if err != nil {
	return err
}
// happy path continues

Avoid unnecessary abstraction

A plain for loop is often clearer than a generic chain. Prefer standard library patterns over frameworks for small services.

Documentation

Document exported symbols; start comments with the name (// User represents ...). Run go doc locally.

Concurrency

Do not hide goroutine lifetimes; tie long work to context.Context.

Testing

Table-driven tests, subtests with t.Run, examples that run as tests when they contain // Output:.