cxuu avatar

Go Interfaces

Go interfaces guidance for accepting interfaces, returning concrete types, and safe type assertions.

CCM score
69 of 100
skills.sh installs
1.4K
GitHub stars
197
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers accept-interfaces and return-concrete-types design, hiding implementations behind interfaces, comma-ok assertions, type switches, and embedding
  • Includes scripts/check-interface-compliance.sh to find exported interfaces that need compile-time var _ I = (*T)(nil) checks, plus reference notes on embedding and receiver types
  • Enforces consumer-owned interfaces and warns against defining interfaces before a real usage example exists
  • Designed for Go projects that need mockable boundaries or abstraction decisions; defers generics-based polymorphism to go-generics

Install

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

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

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{ ... } }

Details

Repository
github.com/cxuu/golang-skills
Category
Go
First seen
May 16, 2026

More from cxuu/golang-skills

All 20

Similar to Go Interfaces

More Go