go-modernize

Modernize legacy Go code with generics, log/slog, errors.Join, and slices/maps helpers.

64|9|Updated Mar 27, 2026
One-click install
npx skills add https://github.com/eduardo-sl/go-agent-skills --skill go-modernize
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-modernize
Source: https://github.com/eduardo-sl/go-agent-skills/tree/main/skills/%28code-quality%29/go-modernize
Command: npx skills add https://github.com/eduardo-sl/go-agent-skills --skill go-modernize

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Modernize legacy Go codebases that still use pre-generics idioms, manual slice/map utilities, unstructured logging, and outdated error handling so they safely adopt newer language features and standard library improvements.

Core Features & Use Cases

  • Generics migration: Replace interface{} utilities with type parameters for type-safe containers and helpers.
  • Structured logging: Migrate ad-hoc log.Printf usage to log/slog for structured logs where appropriate.
  • Error and collection utilities: Replace manual error accumulation with errors.Join and hand-written slice/map loops with slices/maps helpers.
  • Language idioms: Convert classic for-loop patterns to range-over-int and adopt iterators where available.
  • Use Case: Upgrade a service repository from Go 1.16 to Go 1.22+ by updating go.mod, replacing utility code with stdlib features, and following the verification checklist.

Quick Start

Ask the agent to modernize the repository to Go 1.22+, replacing interface{} utilities with generics, switching log.Printf to slog where suitable, using errors.Join for aggregated errors, and applying slices and maps helpers as recommended.

Frequently Asked Questions about go-modernize

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

FAQPage Schema
How do I modernize Go code to use generics instead of interface{}?

Modernize Go code by replacing interface{} utilities with type parameters to create type-safe containers and helpers. This migration targets Go 1.18 through 1.23, shifting pre-generics idioms to standard library features for safer type handling.

What's the best way to migrate unstructured Go logging to log/slog?

Migrate unstructured Go logging by replacing ad-hoc log.Printf usage with log/slog for structured logs where appropriate. This modernization updates legacy Go codebases to standard library structured logging patterns.

Can I use slices and maps helpers to replace manual loops in Go 1.22?

Yes, you can replace hand-written slice and map loops with slices and maps helpers in Go 1.22+. Modernizing Go code involves adopting these standard library utilities to eliminate manual collection operations and reduce boilerplate.

Does Go modernization require updating go.mod compatibility?

Yes, Go modernization requires verifying go.mod compatibility to ensure the codebase targets the correct version. Updating go.mod is essential before applying features like range-over-int patterns, iterators, and errors.Join for aggregated errors.

Why should I use errors.Join instead of manual error accumulation in Go?

Use errors.Join instead of manual error accumulation to aggregate multiple errors using the standard library. Modernizing legacy Go code replaces outdated error handling patterns with errors.Join to simplify error management and improve reliability.

What limitations exist when upgrading a legacy Go codebase to modern patterns?

Upgrading legacy Go codebases requires incremental upgrades and following a verification checklist to avoid breaking changes. Limitations include ensuring go.mod compatibility and verifying that standard library updates like http.NewRequestWithContext do not disrupt existing service behavior.