golang-pitfalls-code-organization

Installation
SKILL.md

Golang Pitfalls: Code & Project Organization

Source material: mistakes #1-16 from 100 Go Mistakes and How to Avoid Them (teivah/100-go-mistakes).

Apply these rules when writing Go code related to code structure, packages, interfaces, and project layout. The number in each heading maps to the corresponding mistake in the book.

1. Unintended variable shadowing (#1)

  • Variable shadowing (redeclaring a name in an inner block) can make code compile while assigning to a different variable than expected.
  • Avoid shadowing; run go vet or a shadowing linter to detect it. Only reusing idiomatic names like err is occasionally acceptable.
  • Prefer unique names in inner scopes.

2. Unnecessary nested code (#2)

  • Reduce nesting; keep the happy path aligned left and return early.
  • If an if block returns, drop the else.
  • Flip conditions so non-happy paths return early:
Installs
2
First Seen
9 days ago
golang-pitfalls-code-organization — fabianoflorentino/golang-agent-skills