go-fix
update Go code for newer API versions
TLDR
SYNOPSIS
go fix [-diff] [-json] [-fixtool=prog] [packages]
DESCRIPTION
go fix updates Go code for newer Go versions. It applies transformations for API changes and deprecated patterns, helping maintain code across Go releases.The tool runs specific fixers (analyzers) that handle known changes between Go versions. As of Go 1.24, go fix uses the same analysis framework as go vet and supports selecting specific analyzers by name.Available analyzers include fixes for: replacing interface{} with any, using min/max builtins, modernizing string operations, updating fmt.Appendf patterns, range-over-int, and more.Files are modified in place by default, so version control is recommended before running.
PARAMETERS
PACKAGES
Packages to fix. Use ./... for all packages in the current module.-diff
Print changes as a unified diff instead of applying them. Useful for CI pipelines.-json
Emit fixes as JSON output instead of applying them.-fixtool prog
Select a different analysis tool with alternative or additional fixers. The default is go tool fix.-v
Verbose output.-n
Print the commands that would be executed but do not run them.-x
Print the commands as they are executed.
CAVEATS
Modifies files in place unless -diff is used. Use version control. May need manual review. Limited to known fixes. Each run analyzes only one build configuration; run with different GOARCH/GOOS values for multi-platform projects.
HISTORY
go fix is part of the Go toolchain. Originally introduced for handling breaking API changes during Go 1.x development, it was significantly enhanced in Go 1.24 to use the analysis framework, gaining support for custom analyzers and modernization fixes.
