with one click
accept-interfaces-return-structs
Core pattern for flexible, testable Go APIs
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Menu
Core pattern for flexible, testable Go APIs
Install with Codex or Claude Copy this prompt, paste it into Codex, Claude, or another assistant, and let it review the skill page and install it for you.
Based on SOC occupation classification
Handle hook scripts and paths for plugin packaging
Package claudefiles components into a valid Claude Code plugin
Package language-specific subsets of claudefiles
Plugin validation errors and fixes
Common channel patterns and idioms
Context cancellation patterns for graceful shutdown
| name | accept-interfaces-return-structs |
| description | Core pattern for flexible, testable Go APIs |
The fundamental Go interface design principle: functions should accept interfaces but return concrete types.
CORRECT - Accept interface, return concrete
type Storage interface {
Save(data []byte) error
}
func NewProcessor(s Storage) *Processor {
return &Processor{storage: s}
}
func (p *Processor) Process(input string) (*Result, error) {
// Returns concrete *Result, accepts Storage interface
return &Result{Value: input}, nil
}
WRONG - Return interface unnecessarily
func NewProcessor(s *FileStorage) Storage {
// Locks caller into interface, prevents direct method access
return &Processor{storage: s}
}
Accepting interfaces:
Returning concrete types:
Return interface when:
func NewLogger(env string) io.Writer {
// Valid: stdlib interface, multiple implementations
if env == "prod" {
return &fileLogger{}
}
return &consoleLogger{}
}
Return interfaces only when: