
This teaches you how to write idiomatic Go using types to prevent bugs at compile time. You'll learn custom types for domain primitives like UserID, functional options for flexible constructors, and when to use interfaces versus structs. The error handling section is minimal but covers the critical bit about wrapping with %w to preserve error chains. It also pushes structured logging with slog instead of printf debugging. The examples are clean and you can copy them directly. If you're coming from dynamic languages or just want to stop passing the wrong ID type to functions, this will save you from entire categories of runtime errors.
$ npx -y skills add 0xbigboss/claude-code --skill go-best-practices --agent claude-codeInstalls into .claude/skills of the current project.
Follows type-first, functional, and error handling patterns from CLAUDE.md. This skill covers language-specific idioms only.
Use Go's type system to prevent invalid states at compile time.
Custom types for domain primitives:
// Distinct types prevent mixing up IDs
type UserID string
type OrderID string
func GetUser(id UserID) (*User, error) {
// Compiler prevents passing OrderID here
}
// Methods attach behavior to the type
func (id UserID) String() string {
return string(id)
}
Interfaces for behavior contracts:
// Define what you need, not what you have
type UserRepository interface {
GetByID(ctx context.Context, id UserID) (*User, error)
Save(ctx context.Context, user *User) error
}
// Accept interfaces, return structs
func ProcessInput(r io.Reader) ([]byte, error) {
return io.ReadAll(r)
}
Enums with iota and exhaustive switch:
type Status int
const (
StatusActive Status = iota + 1
StatusInactive
StatusPending
)
Sponsors