
Go Generics
This skill helps you decide when to use Go generics versus concrete types or interfaces. It walks through a clear decision flow: start concrete, generalize only when you see duplicate logic across multiple types, and prefer interfaces when shared behavior already exists. You'll find practical guidance on constraint composition with tilde and union operators, standard naming conventions for type parameters, and common pitfalls like wrapping standard library types unnecessarily or using generics just to satisfy interfaces. The advice is grounded in the Google Style Guide and emphasizes writing code first, designing types second. Most valuable when you're reaching for `any` with type switches or building reusable data structures that genuinely work across multiple types.
- skills.sh installs
- 1.1K
- GitHub stars
- 193
- last updated
- Aug 21, 2026
Install
$ npx -y skills add cxuu/golang-skills --skill go-generics --agent claude-codeInstalls into .claude/skills of the current project.
Files
Go Generics and Type Parameters
Compatibility: Generics require Go 1.18+.
Resource Routing
references/CONSTRAINTS.md- Read when composing constraints, using type sets, or choosing between generics and interfaces.
When to Use Generics
Start with concrete types. Generalize only when a second type appears.
Prefer Generics When
- Multiple types share identical logic (sorting, filtering, map/reduce)
- You would otherwise rely on
anyand excessive type switching - You are building a reusable data structure (concurrent-safe set, ordered map)
Avoid Generics When
- Only one type is being instantiated in practice
- Interfaces already model the shared behavior cleanly
- The generic code is harder to read than the type-specific alternative
"Write code, don't design types." — Robert Griesemer and Ian Lance Taylor
Decision Flow
Do multiple types share identical logic?
├─ No → Use concrete types
├─ Yes → Do they share a useful interface?
│ ├─ Yes → Use an interface
│ └─ No → Use generics
Bad:
Sponsors
Details
- Repository
- github.com/cxuu/golang-skills
- Categories
- Documentation, Go, Design & UI/UX
- First seen
- Jun 3, 2026
More from cxuu/golang-skills
All 20- Go Declarations1.1K
- Go Code Review1.8K
- Go Testing1.4K
- Go Error Handling1.3K
- Go Linting1.3K
- Go Concurrency1.3K
- Go Interfaces1.3K
- Go Documentation1.3K
- Go Style Core1.3K
- Go Performance1.3K
- Go Context1.3K
- Go Naming1.3K
- Go Defensive1.3K
- Go Packages1.3K
- Go Data Structures1.3K
- Go Functional Options1.3K
- Go Control Flow1.3K
- Go Logging1.1K
- Go Functions1.1K