Go Modernization
Modernize toward the project's intended compatibility target, not automatically toward the newest syntax. Preserve behavior unless the user explicitly includes a behavioral change.
Establish the Target
Before proposing changes:
- Read
go.mod, any go.work, CI configuration, release files, and supported-platform documentation.
- Distinguish the module's
go directive from the locally selected toolchain. Do not assume either one expresses the user's desired support policy.
- If changing the supported Go version is in scope, confirm the target and compatibility consequences. Otherwise, stay within the existing directive.
- Read the official release notes for every version crossed by the upgrade. Use references/versions.md to evaluate candidates without relying on a stale feature catalog.
- Inspect nearby conventions and existing migration decisions before introducing a new idiom.
If the target version or downstream compatibility requirement is materially ambiguous, report the ambiguity before editing version-sensitive code.
Choose Changes by Evidence
Prioritize candidates in this order:
- Removed, deprecated, or behavior-changing APIs that affect correctness or supportability.
- Security and resource-safety improvements supported by the target version.
- Standard-library replacements that remove a dependency or a meaningful amount of custom code.
- Language and testing features that materially simplify the implementation.
- Cosmetic rewrites only when they improve consistency in the touched scope.
Do not replace a mature dependency merely because a standard-library alternative exists. Compare required behavior, migration cost, performance, operational integrations, and supported Go versions.
Work in Reviewable Units
- Keep modernization separate from unrelated features and broad structural refactors.
- For a focused request, change only the requested package or files.
- For a repository-wide review, inventory candidates first, grouped by prerequisite and risk. Apply independent mechanical changes separately from semantic migrations.
- Prefer type-aware tooling for identifier or API rewrites. Inspect every generated diff; reflection, templates, generated files, build tags, and serialized names may not be visible to a type-aware rename.
- Keep ignore files, agent configuration, tool installation, and unrelated dependency upgrades outside a focused code modernization.
Validate Each Migration
Use the project's own commands when present. A typical Go validation sequence is:
gofmt -w <changed-go-files>
go test ./...
go vet ./...
Also run relevant checks when the change warrants them:
go test -race ./... for concurrency semantics.
- Existing integration tests for I/O, database, protocol, or serialization changes.
- Before/after benchmarks for performance-sensitive rewrites.
- Cross-platform or build-tag checks when platform-specific files changed.
go mod tidy only when module contents should change; review its diff separately.
A passing build is not enough for migrations that affect wire formats, random sequences, logging contracts, database behavior, or public APIs. Preserve those contracts explicitly or document an intentional break.
Tooling and Infrastructure
Read references/tooling.md only when the request includes module tooling, CI, compiler diagnostics, vulnerability scanning, or build optimization.
Deliverable
Summarize:
- the target Go version and compatibility assumptions;
- which migrations were applied or proposed, with rationale;
- behavior or API risks that required special verification;
- commands run and any checks that remain unavailable.
1---2name: golang-modernize3description: Modernize Go code for a chosen compatibility target using supported language, standard-library, module, test, and tooling features. Use for Go version upgrades, deprecation cleanup, old-idiom replacement, or a scoped modernization review.4license: MIT5---67# Go Modernization89Modernize toward the project's intended compatibility target, not automatically toward the newest syntax. Preserve behavior unless the user explicitly includes a behavioral change.1011## Establish the Target1213Before proposing changes:14151. Read `go.mod`, any `go.work`, CI configuration, release files, and supported-platform documentation.162. Distinguish the module's `go` directive from the locally selected toolchain. Do not assume either one expresses the user's desired support policy.173. If changing the supported Go version is in scope, confirm the target and compatibility consequences. Otherwise, stay within the existing directive.184. Read the official release notes for every version crossed by the upgrade. Use [references/versions.md](references/versions.md) to evaluate candidates without relying on a stale feature catalog.195. Inspect nearby conventions and existing migration decisions before introducing a new idiom.2021If the target version or downstream compatibility requirement is materially ambiguous, report the ambiguity before editing version-sensitive code.2223## Choose Changes by Evidence2425Prioritize candidates in this order:26271. Removed, deprecated, or behavior-changing APIs that affect correctness or supportability.282. Security and resource-safety improvements supported by the target version.293. Standard-library replacements that remove a dependency or a meaningful amount of custom code.304. Language and testing features that materially simplify the implementation.315. Cosmetic rewrites only when they improve consistency in the touched scope.3233Do not replace a mature dependency merely because a standard-library alternative exists. Compare required behavior, migration cost, performance, operational integrations, and supported Go versions.3435## Work in Reviewable Units3637- Keep modernization separate from unrelated features and broad structural refactors.38- For a focused request, change only the requested package or files.39- For a repository-wide review, inventory candidates first, grouped by prerequisite and risk. Apply independent mechanical changes separately from semantic migrations.40- Prefer type-aware tooling for identifier or API rewrites. Inspect every generated diff; reflection, templates, generated files, build tags, and serialized names may not be visible to a type-aware rename.41- Keep ignore files, agent configuration, tool installation, and unrelated dependency upgrades outside a focused code modernization.4243## Validate Each Migration4445Use the project's own commands when present. A typical Go validation sequence is:4647```bash48gofmt -w <changed-go-files>49go test ./...50go vet ./...51```5253Also run relevant checks when the change warrants them:5455- `go test -race ./...` for concurrency semantics.56- Existing integration tests for I/O, database, protocol, or serialization changes.57- Before/after benchmarks for performance-sensitive rewrites.58- Cross-platform or build-tag checks when platform-specific files changed.59- `go mod tidy` only when module contents should change; review its diff separately.6061A passing build is not enough for migrations that affect wire formats, random sequences, logging contracts, database behavior, or public APIs. Preserve those contracts explicitly or document an intentional break.6263## Tooling and Infrastructure6465Read [references/tooling.md](references/tooling.md) only when the request includes module tooling, CI, compiler diagnostics, vulnerability scanning, or build optimization.6667## Deliverable6869Summarize:7071- the target Go version and compatibility assumptions;72- which migrations were applied or proposed, with rationale;73- behavior or API risks that required special verification;74- commands run and any checks that remain unavailable.