samber avatar

Golang Structs Interfaces

Go struct and interface design guide covering composition, embedding, type assertions, and pointer vs value receivers.

skills.sh installs
41.7K
GitHub stars
3.9K
last updated
Aug 21, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers small interface design, consumer-side interface definition, and when to embed structs versus use named fields
  • Includes a compile-time interface check (var _ io.ReadWriter = (*MyBuffer)(nil)), type switch and comma-ok assertion patterns, and struct field tags
  • Enforces "accept interfaces, return structs" and discourages premature interfaces with a single implementation
  • Designed for Go developers who need guidance on type design when writing or reviewing *.go files

Install

$ npx -y skills add samber/cc-skills-golang --skill golang-structs-interfaces -y

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

Files

Persona: You are a Go type system designer. You favor small, composable interfaces and concrete return types — you design for testability and clarity, not for abstraction's sake.

Community default. A company skill that explicitly supersedes samber/cc-skills-golang@golang-structs-interfaces skill takes precedence.

Go Structs & Interfaces

Interface Design Principles

Keep Interfaces Small

"The bigger the interface, the weaker the abstraction." — Go Proverbs

Interfaces SHOULD have 1-3 methods. Small interfaces are easier to implement, mock, and compose. If you need a larger contract, compose it from small interfaces:

→ See samber/cc-skills-golang@golang-naming skill for interface naming conventions (method + "-er" suffix, canonical names)

type Reader interface {
    Read(p []byte) (n int, err error)
}

type Writer interface {
    Write(p []byte) (n int, err error)
}

// Composed from small interfaces
type ReadWriter interface {
    Reader
    Writer
}

Compose larger interfaces from smaller ones:

type ReadWriteCloser interface {
    io.Reader
    io.Writer
    io.Closer
}

Define Interfaces Where They're Consumed

Details

Repository
github.com/samber/cc-skills-golang
Category
Go
First seen
Apr 16, 2026

More from samber/cc-skills-golang

All 47

Similar to Golang Structs Interfaces

More Go