LinuxCommandLibrary

goimports

Go import line management and formatting

TLDR

Format and fix imports in a file

$ goimports [file.go]
copy
Fix imports and write to file
$ goimports -w [file.go]
copy
Show diff of changes
$ goimports -d [file.go]
copy
List files with import issues
$ goimports -l [file.go]
copy
Separate local packages
$ goimports -local [github.com/myorg] [file.go]
copy
Format all files in directory
$ goimports -w .
copy

SYNOPSIS

goimports [flags] [path ...]

DESCRIPTION

goimports updates Go import lines by adding missing imports and removing unreferenced ones. It also formats code in the same style as gofmt, making it a drop-in replacement.
Imports are grouped with standard library first, then third-party packages, and sorted alphabetically within each group. The -local flag allows separating project-specific imports into their own group.

PARAMETERS

-d

Display diffs instead of rewriting.
-l
List files whose imports differ.
-w
Write result to source file.
-local prefix
Comma-separated prefixes for local packages.
-e
Report all errors.
-srcdir dir
Source directory for import resolution.

SEE ALSO

gofmt(1), go-fmt(1)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community