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-code

Installs 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 any and 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
1kostja94 avatarmigration-page-generatorkostja94/marketing-skillsWhen the user wants to create, optimize, or audit migration guides for users switching from competitors. Also use when the user mentions "migration guide," "mig1.1Kskills.sh installs
2mblode avataragent-skills-creatormblode/agent-skillsGuides creation and improvement of best-practice agent skills following the open format specification. Covers frontmatter, progressive disclosure, reference fil1Kskills.sh installs
3inference-sh avatarog-image-designinference-sh/skillsOpen Graph and social sharing image design with platform specs, text placement, and branding. Covers OG meta tags, Twitter cards, LinkedIn previews, and dynamic1Kskills.sh installs
4tencentcloudbase avatarauth-tool-cloudbasetencentcloudbase/skillsCloudBase auth provider configuration and login-readiness guide. This skill should be used when users need to inspect, enable, disable, or configure auth provid1Kskills.sh installs
5inference-sh avatartwitter-thread-creationinference-sh/skillsTwitter/X thread writing with hook tweets, thread structure, and engagement optimization. Covers tweet formatting, character limits, media attachments, and post1Kskills.sh installs
6dodopayments avatardodo-best-practicesdodopayments/skillsGuide for initial Dodo Payments setup, including SDK installation, test and live environments, API keys, and the canonical checkout-to-webhook architecture.1Kskills.sh installs