go-interfaces
Go interface design patterns and best practices
When & Why to Use This Skill
This Claude skill provides expert guidance on Go (Golang) interface design patterns and best practices. It helps developers master core concepts such as implicit satisfaction, consumer-driven design, and composition patterns to build decoupled, maintainable, and scalable software. By focusing on the 'accept interfaces, return structs' principle and identifying 'interface pollution,' it ensures robust architectural integrity in Go projects.
Use Cases
- Refactoring legacy Go codebases to improve decoupling by shifting interface definitions from the producer to the consumer side.
- Designing clean and idiomatic API boundaries using the 'accept interfaces, return structs' pattern to maximize flexibility.
- Auditing projects for 'interface pollution' to remove unnecessary abstractions and simplify the overall code structure.
- Implementing complex system behaviors through interface composition and embedding techniques to expand method sets efficiently.
- Establishing team-wide coding standards for Go interface usage to ensure consistency and high-quality software architecture.
| name | go-interfaces |
|---|---|
| description | Go interface design patterns and best practices |
Interface Design
Master Go's approach to interfaces: implicit satisfaction, consumer-driven design, and composition patterns.
Route by Concern
Accept/return patterns → see design/
- Accept interfaces, return structs principle
- When to deviate from the rule
Interface pollution → see pollution/
- Detecting unnecessary abstractions
- Premature interface creation
Embedding patterns → see embedding/
- Interface composition techniques
- Method set expansion
Quick Check
- Interface defined by consumer, not producer
- Keep interfaces small (<5 methods)
- Return concrete types from functions
- No interface{} unless truly necessary