From golang-workflow
Core pattern for flexible, testable Go APIs
npx claudepluginhub jamesprial/prial-plugins --plugin golang-workflowThis skill uses the workspace's default tool permissions.
The fundamental Go interface design principle: functions should accept interfaces but return concrete types.
Guides Go interface design patterns: consumer-side definition, accept-interfaces-return-structs, composition, implicit satisfaction, and pitfalls. For decoupling packages, defining contracts, reviewing usage, refactoring for testability.
Guides Go interface usage: defining/implementing, abstractions, mockable testing boundaries, embedding, accepting interfaces vs concrete returns, type assertions/switches. Includes compliance check script.
Guides Go interface usage: design, implicit implementation, duck typing, composition, empty interfaces, type assertions, Stringer, error for flexible APIs and abstractions.
Share bugs, ideas, or general feedback.
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: