What problem does it solve?
It solves confusion and recurring mistakes when designing Go type systems, especially around how to structure structs and interfaces for clarity, testability, and correct runtime behavior.
Core Features & Use Cases
- Small, composable interfaces: Prefer 1–3 method interfaces and compose larger contracts from smaller ones.
- Interfaces defined at the consumer: Define interfaces in the package that needs to consume the dependency, not where it’s implemented.
- Accept interfaces, return structs: Accept interface parameters for flexibility, but return concrete types from constructors for clarity.
- Safe and expressive type behavior: Use comma-ok type assertions and type switches, plus optional-capability checks via type assertions.
- Robust struct design: Make the zero value useful, add field tags for serialization, use compile-time interface checks, keep receiver types consistent, and prevent accidental struct copies with the noCopy sentinel.
- Pointer vs value receivers and embedding rules: Choose receivers consistently and embed only when you want to promote the full inner API (“is a”), otherwise use named fields (“has a”).
Quick Start
Use the golang-structs-interfaces skill to review a proposed Go API and refactor the structs, interfaces, receivers, and serialization tags to match best practices for safe composition and maintainable type contracts.