Go tools
Example
GoLand integrates essential Go tools to help you write, format, analyze, and generate code more efficiently. This topic shows you how to use the most popular Go tools inside the IDE.
gofmt
GoLand includes built-in import management and a code formatter. Imports are handled on the fly. To customize how imports are processed, open settings by pressing Ctrl+Alt+S and navigate to
.To reformat code, press Ctrl+Alt+L. Unlike gofmt
, the GoLand formatter works with incomplete or syntactically incorrect code and can be applied to selected blocks. It also supports advanced formatting options such as inserting semicolons automatically, wrapping parameters, and more.
To run both formatters at once, enable the On Reformat Code action option under on the Other tab.
You can also enable Reformat code in Actions on Save. This option is enabled by default. When you press Ctrl+S, the IDE runs both the built-in formatter and gofmt
.
Use gofmt
to format Go source code in the current file or across the whole project.
To format code in the currently opened file, navigate to
.To format all code in the project, navigate to
.To format code before committing changes to VCS, select the Go fmt checkbox in the Commit dialog. For more information, refer to Commit and push changes to Git repository.
goimports
GoLand includes built-in import management and a code formatter. Imports are handled on the fly. To customize how imports are processed, open settings by pressing Ctrl+Alt+S and navigate to
.Use goimports
to automatically add missing and remove unused imports.
To apply
goimports
, navigate to .
If goimports
is not available in your project, click the go install goimports
link in the notification. Alternatively, open the Terminal tool window ( ) and run:
go generate
Use the go generate
command and the //go:generate
directive to run code generation tools.
Add a directive to your code:
//go:generate command argumentsFor example:
//go:generate stringer -type=Pill
Run
go generate
from the IDE:Or use the gutter icon
and select Go Generate
go vet
Use go vet
to identify possible bugs and suspicious constructs in Go source files.
To run
go vet
, navigate to . The output will appear in the Terminal tool window.