Idiomatic Go Patterns Review
By snoozeButtonKing · Published · Updated
Reviews Go code for the habits that cause production trouble: lost error context, leaked goroutines, misused contexts, bloated interfaces, and tangled packages.
Prompt template
## Idiomatic Go Patterns Review Review this Go code the way an experienced maintainer would. - The code: [textarea: Paste the package or files] - What it does: [text: Service or library and its role] - Go version: [text: e.g. 1.22] - Concerns: [multi: Error wrapping, Context use, Goroutine lifetimes, Interfaces, Package layout, Concurrency safety, Testing] - Review depth: [dropdown: Quick scan, Standard, Line by line] Check errors first: every returned error should be handled or wrapped with %w and a short message saying what was being attempted, and callers should compare with errors.Is or errors.As rather than strings. Next, context: it should be the first parameter, passed down, and respected by blocking calls and loops. For goroutines, ask for each one who stops it and how, and look for leaks, unguarded shared state, and channels that are never closed or read. For interfaces, prefer small ones defined where they are used, and flag ones defined next to the only implementation. For layout, flag import cycles risk, package names that repeat their contents, and an internal directory that is missing. List findings from most to least harmful, each with the line, why Go readers would object, and a corrected snippet. End with the three changes that would improve the package most.