cxuu avatar

Go Interfaces

Covers the practical side of Go interfaces: where to define them (consumer's package, not producer's), when to use pointer versus value receivers, and how to write compile-time satisfaction checks with the `var _ I = (*T)(nil)` pattern. Includes a script that scans your codebase for missing interface compliance checks, which is genuinely useful for catching drift. The "accept interfaces, return concrete types" guidance is the most important bit here, and it's explained clearly with good and bad examples. Also covers type assertions, type switches, and embedding gotchas. If you're writing testable Go or designing package boundaries, this gives you the idioms you need without the usual blog post fluff.

skills.sh installs
1.3K
GitHub stars
193
last updated
Aug 21, 2026

Install

$ npx -y skills add cxuu/golang-skills --skill go-interfaces --agent claude-code

Installs into .claude/skills of the current project.

Files

Go Interfaces and Composition

Resource Routing

  • scripts/check-interface-compliance.sh - Run as a heuristic to find exported interfaces that may need compile-time assertions.
  • scripts/check-interface-compliance.go - Implementation helper invoked by check-interface-compliance.sh; patch this when changing method-set analysis.
  • references/EMBEDDING.md - Read when embedding interfaces or structs in public APIs.
  • references/RECEIVER-TYPE.md - Read when pointer/value receivers affect interface satisfaction.

Accept Interfaces, Return Concrete Types

Interfaces belong in the package that consumes values, not the package that implements them. Return concrete (usually pointer or struct) types from constructors so new methods can be added without refactoring.

// Good: consumer defines the interface it needs
package consumer

type Thinger interface { Thing() bool }

func Foo(t Thinger) string { ... }
// Good: producer returns concrete type
package producer

type Thinger struct{ ... }
func (t Thinger) Thing() bool { ... }
func NewThinger() Thinger { return Thinger{ ... } }

Sponsors

Details

Repository
github.com/cxuu/golang-skills
Categories
Testing & QA, AI & Agent Building, Go
First seen
May 16, 2026

More from cxuu/golang-skills

All 20
1alirezarezvani avatarsenior-securityalirezarezvani/claude-skillsUse when the user asks for STRIDE threat modeling, DREAD risk scoring, data-flow-diagram threat analysis, or a quick secret scan — or when a security request ne1.3Kskills.sh installs
2cxuu avatargo-style-corecxuu/golang-skillsUse when working with Go formatting, line length, nesting, naked returns, semicolons, or core style principles. Also use when a style question isn't covered by 1.3Kskills.sh installs
3nvidia avatarjetson-diagnosticnvidia/skillsRead-only Jetson health snapshot for identity, memory, GPU, thermal, power, storage, services, and top processes.1.3Kskills.sh installs
4astronomer avatarauthoring-dagsastronomer/agentsWorkflow and best practices for writing Apache Airflow DAGs. Use when creating a new DAG, write pipeline code, handling questions about DAG patterns and convent1.3Kskills.sh installs
5kostja94 avatarindexingkostja94/marketing-skillsWhen the user wants to fix indexing issues from Search Console, use noindex, or implement Google Indexing API. Also use when the user mentions "fix indexing," "1.3Kskills.sh installs
6agentmc15 avatartrading-strategiesagentmc15/polymarket-traderFramework for developing, testing, and deploying trading strategies for prediction markets. Use when creating new strategies, implementing signals, or building 1.3Kskills.sh installs