go-modernize

Upgrade Go code to modern idioms using language features and standard library improvements from Go 1.21 through 1.26.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill go-modernize-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-modernize
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/go/go-modernize
Command: npx skills add https://github.com/asarchami/dotfiles --skill go-modernize-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go codebases accumulate outdated patterns as the language evolves, missing safer, faster replacements shipped in each release. This Skill systematically identifies deprecated APIs, legacy idioms, and missed standard library improvements, prioritizing safety and correctness fixes over cosmetic changes. ## Core Features & Use Cases - Inline modernization suggestions: While writing or reviewing Go code, propose relevant upgrades scoped to the current file, such as replacing math/rand with math/rand/v2 or interface{} with any. - Full codebase scans: Run parallel category-based scans covering deprecated packages, language features, standard library upgrades, testing patterns, and tooling, integrated with the golangci-lint modernize linter. - Ignore tracking: Record dismissed suggestions in a .modernize file so they are never re-proposed. - Use Case: During a code review, you notice a project on Go 1.22 still using sort.Slice and manual loop-variable copies. The Skill suggests slices.SortFunc, removes the shadow copies, and flags that upgrading to Go 1.24 would unlock os.Root for safer file handling. ## Quick Start Ask the assistant to scan this Go project for modernization opportunities and prioritize the safety fixes first.

Frequently Asked Questions about go-modernize

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

FAQPage Schema
How do I modernize legacy Go code to use newer language features?

Run a full scan that checks deprecated packages, language features like range-over-int and iterators, and standard library upgrades such as slices, maps, and slog. Suggestions are prioritized with safety fixes first, and the golangci-lint modernize linter automates detection.

What replaces math/rand in modern Go?

math/rand/v2 replaces math/rand starting in Go 1.22. It removes the need for rand.Seed, renames Intn to IntN, adds generic functions like rand.N[T], and uses better algorithms such as ChaCha8 and PCG.

Does Go 1.22 fix the loop variable capture bug?

Yes, Go 1.22 gives each loop iteration a new variable, so shadow copies like v := v inside loops can be removed. The go directive in go.mod must be set to go 1.22 or later for this behavior to apply.

Can I prevent ignored modernization suggestions from reappearing?

Yes, explicitly ignored suggestions are appended to a .modernize file in the project root with the date, category, and description. Every scan reads this file first and excludes all listed items from its output.

What Go versions does this modernization guidance cover?

The guidance covers Go 1.21 through Go 1.26, released between 2023 and 2026, plus a few older still-missed improvements like any and errors.Is. Projects on Go 1.20 or earlier should upgrade their Go version first.

Should I migrate from zap or logrus to log/slog?

For new projects, prefer the standard library log/slog introduced in Go 1.21. For existing projects heavily invested in zap or logrus, migration is optional and ranked as a lower-priority gradual improvement.