goimportx

goimportx 能够帮忙开发者很好的治理 golang 的分组

个性

  • 主动对 go 导入进行排序和分组。
  • 反对自定义组规定。
  • 反对将后果写入文件。
  • 仅反对 go module。
  • 应用Go语言官网排序算法。
  • 只有一个 import 时主动删除括号。
  • 主动删除反复的空换行符。

装置

go install github.com/anqiansong/goimportx@latest

应用

goimportx --file /path/to/file.go

帮忙命令

goimportx --helpsort and group go importsUsage:  goimportx [flags]Examples:goimportx --file /path/to/file.go --group "system,local,third"Flags:  -f, --file string    file path  -g, --group string   group rule, split by comma, only supports [system,local,third,others] (default "system,local,third")  -h, --help           help for goimportx  -v, --version        version for goimportx  -w, --write          write result to (source) file instead of stdout

有了 goimports,为什么还须要 goimportx

  • 补救 goimports 只能按 零碎包,三方包 分组的有余,goimportx 反对依照 零碎包本地包三方包 分组
  • 补救 goimports 不能移出空行问题
  • 解决多个 import block 不能合并到一个 import block 问题