language-go
Installation
SKILL.md
Go
Errors are values
- Return
error; do notpanicacross package boundaries. - Wrap with
fmt.Errorf("doing X: %w", err)to preserve the chain. - Inspect with
errors.Isanderrors.As. Never string-match messages. - Sentinel errors (
var ErrNotFound = errors.New(...)) for expected cases; typed errors when callers need structured data.
if err != nil {
return fmt.Errorf("load user %s: %w", id, err)
}
Interfaces — small, defined by the consumer
- Define interfaces in the package that uses them, not where concrete types live.
- Single-method interfaces are normal (
io.Reader,io.Closer). - Accept interfaces, return concrete types.