Linux command
go-fix 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Fix all packages in the current module
go fix ./...
Fix a specific package
go fix [package]
Preview changes as a unified diff without modifying files
go fix -diff [package]
Output fixes as JSON instead of applying them
go fix -json [package]
Use a custom fix tool
go fix -fixtool=[prog] [package]
说明
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.
参数
- -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.
FAQ
What is the go-fix command used for?
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.
How do I run a basic go-fix example?
Run `go fix ./...` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -diff do in go-fix?
Print changes as a unified diff instead of applying them. Useful for CI pipelines.