golang-modernize

Modernize Go codebases by replacing outdated patterns with current language features and standard library APIs.

1|Updated May 25, 2020
One-click install
npx skills add https://github.com/titaneric/dotfiles --skill golang-modernize-titaneric
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: golang-modernize
Source: https://github.com/titaneric/dotfiles/tree/main/dot_agents/skills/golang-modernize
Command: npx skills add https://github.com/titaneric/dotfiles --skill golang-modernize-titaneric

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Go codebases accumulate outdated patterns as the language evolves, leaving teams with deprecated APIs, missed safety fixes, and verbose idioms that newer Go versions solve natively. This Skill systematically detects and applies modernizations across Go 1.21 through 1.26, prioritizing safety and correctness fixes before cosmetic improvements. ## Core Features & Use Cases - Version-aware modernization: Reads go.mod to suggest only changes valid for the project's Go version, covering deprecated package migrations (math/rand to math/rand/v2), language features (min/max builtins, range-over-int, iterators), and standard library upgrades (slices, maps, cmp, slog). - Prioritized migration guidance: Ranks changes by impact, putting security fixes like os.Root path traversal prevention and govulncheck scans ahead of readability improvements like interface{} to any. - Inline and full-scan modes: Suggests contextual improvements while coding, or runs a five-agent parallel codebase scan applied in an isolated worktree for explicit /golang-modernize invocations. - Use Case: A team upgrading from Go 1.21 to 1.25 invokes the skill to remove loop variable shadow copies, adopt sync.WaitGroup.Go, replace gorilla/mux with stdlib http.ServeMux routing, and drop the automaxprocs dependency. ## Quick Start Ask the agent to review your Go project for modernization opportunities based on the version in go.mod.

Frequently Asked Questions about golang-modernize

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

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

Check the go directive in go.mod first, then apply version-appropriate changes: min/max builtins and slices package for 1.21, range-over-int and math/rand/v2 for 1.22, iterators for 1.23, os.Root and b.Loop() for 1.24, and sync.WaitGroup.Go for 1.25. The modernize linter in golangci-lint v2.6.0+ automates detection.

How to migrate from math/rand to math/rand/v2 in Go?

Change the import to math/rand/v2, rename Intn to IntN and Int63n to Int64N, and remove all rand.Seed calls since v2 seeds automatically. The Read function was removed, so use crypto/rand for random bytes instead.

Does Go 1.25 still need uber automaxprocs?

No. Go 1.25 added built-in container-aware GOMAXPROCS that respects cgroup CPU limits on Linux, making the go.uber.org/automaxprocs dependency unnecessary. Remove the import and run go mod tidy to clean up go.sum.

What is the difference between omitempty and omitzero in Go JSON tags?

omitempty does not omit zero time.Time values because a struct is never considered empty, and it treats false booleans as empty. Go 1.24 introduced omitzero, which correctly omits zero time.Time values and handles bool and custom types as expected.

When should I use runtime.AddCleanup instead of SetFinalizer?

Use runtime.AddCleanup in Go 1.24+ for all new cleanup code. Unlike SetFinalizer, it takes the resource as a separate argument rather than the whole object, avoiding the cycle restriction where finalizers prevent garbage collection of self-referencing objects.

Can gorilla/mux be replaced with the Go standard library?

Yes, for Go 1.22+. The stdlib http.ServeMux supports method-prefixed patterns like "GET /api/users/{id}" and path parameters via r.PathValue("id"), covering common REST routing needs without third-party dependencies.