Goland 配置 go fmt 和 goimports

3,045 阅读1分钟

Goland 配置 go fmt 和 goimports

1. go fmt 简介

go fmt 是自动格式化 Go 源代码的工具。

# 1. 直接使用 gofmt 工具
gofmt -w yourcode.go
# 2. 使用 go fmt 命令
go fmt path/to/your/package

2. goimports 简介

goimports 更新您的 Go 导入包,添加丢失的包并删除未引用的包。

3. goland 配置go fmt 和 goimports

File → Settings → Tools → File Watchers → “+”

Untitled.png