golang

Guides Go development decisions on error handling, structured logging, transactions, and testing.

Updated Jan 30, 2026
One-click install
npx skills add https://github.com/RyoMa99/chezmoi_dotfiles --skill golang-ryoma99
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang
Source: https://github.com/RyoMa99/chezmoi_dotfiles/tree/main/dot_claude/skills/golang
Command: npx skills add https://github.com/RyoMa99/chezmoi_dotfiles --skill golang-ryoma99

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go developers repeatedly face ambiguous design choices—how to structure errors across layers, when to introduce Unit of Work, how to keep secrets out of logs, and how to organize cobra CLIs. This Skill provides decision flows and concrete patterns for these recurring Go design questions. ## Core Features & Use Cases - Error Design Decision Flow: Chooses between fmt.Errorf wrapping, sentinel errors, and custom error types, with Split-Brain Error Types separating internal details from user-facing messages. - Structured Logging with slog: Covers LogValuer-based secret redaction, Canonical Log Lines, log level judgment, and avoiding duplicate error logging across layers. - Transaction Management: Staged adoption from single-repository Tx callbacks to Unit of Work, explicitly avoiding context-based transaction propagation. - Testing & CLI Conventions: Standard-library-only table-driven tests, gotestsum via go tool, and cobra CLI principles like NewRootCmd factories and logic separation. - Use Case: When designing a new Go HTTP service, consult this Skill to decide error translation at layer boundaries, set up slog with secret masking, and structure repository transactions. ## Quick Start Ask the AI to review your Go code's error handling and logging design using the golang skill's decision flows and patterns.

Frequently Asked Questions about golang

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I choose between sentinel errors and custom error types in Go?

Use fmt.Errorf wrapping when callers don't need to distinguish error kinds, sentinel errors (var ErrNotFound) for two to three distinguishable kinds, and custom error structs when you have many kinds or need attached context. Add Split-Brain Error Types when users need separate safe messages.

How to prevent passwords from appearing in Go slog logs?

Implement slog.LogValuer on your structs using an allow-list that only exports safe fields, or define a Secret string type whose LogValue and String methods return [REDACTED]. This masks secrets in both slog output and fmt printing using only the standard library.

When should I use Unit of Work instead of repository transactions in Go?

Start with a single repository Tx callback method, which covers most cases. Only adopt Unit of Work when a transaction must atomically span multiple repositories and neither aggregate redesign nor eventual consistency with async processing can avoid it.

Should I use testify for Go testing?

This Skill recommends the standard library only: use t.Fatalf for preconditions where failure makes subsequent checks meaningless, and t.Errorf for validations so multiple failures surface at once. Write table-driven tests with t.Run from the start, even with a single case.

Why avoid propagating transactions through context.Context in Go?

The Transactor pattern using context.WithValue loses type safety and makes transaction boundaries implicit and hard to trace. Prefer explicit passing via DBTX interfaces or Unit of Work callbacks so transaction scope is visible in function signatures.

How do I structure a cobra CLI for testability in Go?

Keep cobra as wiring only: put business logic in an internal app package, use a NewRootCmd factory instead of global command variables so each test gets an isolated command tree, and confine viper to a config package that returns a validated struct.