samber avatar

Golang Structs Interfaces

A solid reference for Go's type system that covers the practical patterns you actually need: small composable interfaces, "accept interfaces return structs," embedding semantics, type assertions with comma-ok, and compile-time interface checks. It's opinionated in the right ways (no premature interfaces, consumers define contracts, generics over `any`) and includes the rationale behind each rule. Useful when you're designing a new API surface, choosing between pointer and value receivers, or trying to remember whether to embed or use a named field. The struct tag and dependency injection coverage fills out the common scenarios. Written by samber, who maintains a solid collection of Go skills.

skills.sh installs
41.3K
GitHub stars
3.8K
last updated
Aug 21, 2026

Install

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

Installs into .claude/skills of the current project.

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

Sponsors

Details

Repository
github.com/samber/cc-skills-golang
Categories
Documentation, AI & Agent Building, Go, Design & UI/UX
First seen
Apr 16, 2026

More from samber/cc-skills-golang

All 47
1samber avatargolang-benchmarksamber/cc-skills-golangGolang benchmarking, profiling, and performance measurement. Use when writing, running, or comparing Go benchmarks, profiling hot paths with pprof, interpreting41Kskills.sh installs
2samber avatargolang-dependency-injectionsamber/cc-skills-golangComprehensive guide for dependency injection (DI) in Golang. Covers why DI matters (testability, loose coupling, separation of concerns, lifecycle management), 41Kskills.sh installs
3pexoai avatarpexo-agentpexoai/pexo-skillsAI video generation skill with auto model selection across Seedance 2, Kling 3.0, HappyHorse, and 10+ models. Produces finished multi-shot videos (5–120s) from 40.6Kskills.sh installs
4wshobson avatarpython-testing-patternswshobson/agentsImplement comprehensive testing strategies with pytest, fixtures, mocking, and test-driven development. Use when writing Python tests, setting up test suites, o40Kskills.sh installs
5heygen-com avatarstyle-samplingheygen-com/hyperframesMake a new episode in a proven video style - Collage Explainer, Finance Explainer, Animated Science Explainer, 3D Brand Explainer, 3D True Crime - on the person38.8Kskills.sh installs
6samber avatargolang-spf13-cobrasamber/cc-skills-golangGolang CLI command tree library using spf13/cobra — cobra.Command, RunE vs Run, PersistentPreRunE hook chain, Args validators (NoArgs, ExactArgs, MatchAll, cust38.6Kskills.sh installs