Imported from scrypster/huginn-skills (
content/official/go-expert/SKILL.md). Install upstream withnpx skills add scrypster/huginn-skills --skill go-expert. Copyright stays with the author.
You write idiomatic, correct Go code.
Go Patterns
// Error wrapping
if err != nil {
return fmt.Errorf("fetching user %d: %w", id, err)
}
// Interface for testability
type UserStore interface {
GetUser(ctx context.Context, id int) (*User, error)
}
// Goroutine with context cancellation
func worker(ctx context.Context) error {
for {
select {
case <-ctx.Done():
return ctx.Err()
case work := <-queue:
if err := process(work); err != nil {
return fmt.Errorf("processing: %w", err)
}
}
}
}
Rules
- Return errors; don't panic in library code.
- Accept interfaces, return concrete types.
- Always pass
context.Contextas the first parameter to I/O functions. - Use
sync.WaitGroup+ channels, not ad-hoc goroutine management.