LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

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 (not just the first 10 on different lines).
-format-only
Do not fix imports; only format the code. In this mode goimports is effectively gofmt with grouped imports.
-v
Verbose logging.
-srcdir dir
Choose imports as if source code is from the specified directory.

INSTALL

sudo apt install golang-golang-x-tools
copy
brew install goimports
copy

SEE ALSO

gofmt(1), go-fmt(1), gofumpt(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid