What problem does it solve?
It helps you design Go structs and interfaces that stay maintainable, testable, and correct—avoiding common pitfalls like bloated interfaces, premature abstractions, unsafe type assertions, and broken zero values.
Core Features & Use Cases
- Small, composable interfaces: Prefer 1–3 method interfaces and compose larger contracts from smaller ones.
- Interface ownership and DI: Define interfaces where they are consumed, and inject dependencies via interfaces in constructors.
- Practical correctness patterns: Return concrete types from constructors, make the zero value useful (lazy init), and verify interfaces at compile time.
- Safe runtime behavior: Use comma-ok type assertions and type switches; use type assertions for optional capabilities (e.g., flush when supported).
- Struct composition rules: Use embedding to promote an inner type’s API when appropriate, otherwise use named fields to keep dependencies internal.
- Receiver and copying safety: Keep pointer/value receiver choices consistent and prevent accidental copying with the noCopy sentinel.
- Type-safety guidance: Prefer generics over any/interface{} except at true boundaries like reflection/JSON decoding.
Quick Start
Use the golang-structs-interfaces skill when you are defining Go structs or interfaces and want guidance on composition, dependency injection, serialization tags, safe assertions, and pointer vs value receiver design.