Go Data Types & Control Flow
Correct patterns for Go's built-in data types (slices, maps, integers), control structures (range loops, break, defer), and string handling (runes, UTF-8, conversions).
When to Use This Skill
- Working with slices and maps (initialization, capacity, memory leaks)
- Iterating with range loops (variable capture, pointer reuse)
- Handling integers (overflow, octal literals, floating point)
- Manipulating strings (runes, trim, substring leaks)
- Using defer inside loops
How It Works
- Identifies data type and control flow anti-patterns
- Explains subtle Go semantics (nil vs empty slice, range variable reuse)
- Shows correct implementations with working examples
- Categorized by impact level
Categories Covered
- Data Types — slices, maps, integers, floating point, nil/empty slice
- Control Structures — range loops, defer in loops, break, map iteration
- Strings — runes, UTF-8, trim functions, substring memory leaks
Present Results to User
When identifying issues:
❌ Found: Range loop variable captured by closure
📍 Location: handlers/batch.go:34
⚠️ Impact: HIGH - All goroutines reference same variable
✅ Fix: Copy loop variable before passing to goroutine
[Show incorrect code]
[Show correct code]
[Explain why the fix matters]
Troubleshooting
Nil vs empty slice confusion:
- Both have length 0, but nil slice marshals to
null in JSON; empty slice marshals to []
- Use
var s []T for nil slice, s := []T{} or make([]T, 0) for empty
1---2name: go-data3description: Use this skill when working with Go slices, maps, integers, strings, range loops, or defer in loops to avoid common data type and control flow pitfalls.4---56# Go Data Types & Control Flow78Correct patterns for Go's built-in data types (slices, maps, integers), control structures (range loops, break, defer), and string handling (runes, UTF-8, conversions).910## When to Use This Skill1112- Working with slices and maps (initialization, capacity, memory leaks)13- Iterating with range loops (variable capture, pointer reuse)14- Handling integers (overflow, octal literals, floating point)15- Manipulating strings (runes, trim, substring leaks)16- Using defer inside loops1718## How It Works19201. Identifies data type and control flow anti-patterns212. Explains subtle Go semantics (nil vs empty slice, range variable reuse)223. Shows correct implementations with working examples234. Categorized by impact level2425## Categories Covered26271. **Data Types** — slices, maps, integers, floating point, nil/empty slice282. **Control Structures** — range loops, defer in loops, break, map iteration293. **Strings** — runes, UTF-8, trim functions, substring memory leaks3031## Present Results to User3233When identifying issues:34```35❌ Found: Range loop variable captured by closure36📍 Location: handlers/batch.go:3437⚠️ Impact: HIGH - All goroutines reference same variable38✅ Fix: Copy loop variable before passing to goroutine3940[Show incorrect code]41[Show correct code]42[Explain why the fix matters]43```4445## Troubleshooting4647**Nil vs empty slice confusion:**48- Both have length 0, but nil slice marshals to `null` in JSON; empty slice marshals to `[]`49- Use `var s []T` for nil slice, `s := []T{}` or `make([]T, 0)` for empty