Files
tldr/pages.zh/common/goimports.md

20 lines
568 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# goimports
> 更新 Go 导入行,添加缺失的导入并删除未引用的导入。
> 更多信息:<https://godoc.org/golang.org/x/tools/cmd/goimports>。
- 显示完成的导入源文件:
`goimports {{path/to/file.go}}`
- 将结果写回源文件,而不是 `stdout`
`goimports -w {{path/to/file.go}}`
- 显示差异并将结果写回源文件:
`goimports -w -d {{path/to/file.go}}`
- 设置第三方包后的导入前缀字符串(以逗号分隔的列表):
`goimports -local {{path/to/package1,path/to/package2,...}} {{path/to/file.go}}`