go-idioms

Guides Go implementation, refactoring, and review using version-gated official idioms.

Updated Jul 4, 2023
One-click install
npx skills add https://github.com/kohdice/dotfiles --skill go-idioms-kohdice
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: go-idioms
Source: https://github.com/kohdice/dotfiles/tree/main/config/agents/skills/go-idioms
Command: npx skills add https://github.com/kohdice/dotfiles --skill go-idioms-kohdice

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Go codebases often mix outdated patterns with modern APIs, and recommendations that ignore the module's declared go directive can break builds or miss available improvements. This Skill ensures every Go recommendation is grounded in official sources and compatible with the project's actual Go version. ## Core Features & Use Cases - Version-gated recommendations: Reads the module's go.mod directive first and never suggests language features or stdlib APIs introduced after that version, presenting newer options as clearly labeled upgrade-gated alternatives. - Modern idiom catalog: Provides a verified catalog of idioms from Go 1.18 through 1.26, including slices/maps replacements, range-over-func iterators, log/slog, math/rand/v2, and testing modernizations like b.Loop() and t.Context(). - Deprecation detection: Flags deprecated APIs such as io/ioutil, httputil.ReverseProxy.Director, and crypto/rsa PKCS #1 v1.5 encryption with their official replacements. - Use Case: When reviewing a pull request in a module declaring go 1.21, the Skill flags sort.Slice usage for slices.Sort, but presents wg.Go (1.25) only as an upgrade-gated option rather than an apply-now finding. ## Quick Start Review this Go module for outdated idioms and modernization opportunities, respecting its go.mod version.

Frequently Asked Questions about go-idioms

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

FAQPage Schema
How do I modernize Go code to use newer standard library features?▼

Modernize Go code by first checking the go directive in go.mod, then replacing legacy patterns with std equivalents available at that version, such as sort.Slice with slices.Sort (1.21) or interface{} with any (1.18). APIs introduced after the directive version must be treated as upgrade-gated options.

What Go idioms replace deprecated packages like io/ioutil?▼

io/ioutil functions map to os and io equivalents, deprecated since Go 1.16. Other deprecations include httputil.ReverseProxy.Director replaced by Rewrite in 1.26, and crypto/rsa PKCS #1 v1.5 encryption replaced by OAEP.

Does the go directive in go.mod affect which language features I can use?▼

Yes, the go directive gates which language features and stdlib APIs apply to a module. You must never use an API introduced strictly after the directive version, though APIs introduced exactly at that version are available.

How do I handle Go version compatibility in a multi-module workspace?▼

In a go.work workspace, resolve the go directive of the specific module that owns the file being edited, not the workspace file. Each module's directive independently gates which recommendations apply to its code.

When should I replace math/rand with math/rand/v2?▼

Replace math/rand with math/rand/v2 when the go directive is 1.22 or higher, gaining rand.N and rand.IntN without seeding. Preserve the existing generator when callers depend on its exact historical output sequence, since v2 changes output streams.

What testing modernizations are available in recent Go versions?▼

Go 1.24 adds b.Loop() for benchmarks, t.Context() for test cancellation, and t.Chdir for directory changes. Go 1.25 adds testing/synctest for concurrency tests, and 1.26 adds T.ArtifactDir for test outputs.