GoLand 2025.1 Help

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 Go | Imports.

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 Editor | Code Style | Go 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 Tools | Go Tools | Go Fmt File.

  • To format all code in the project, navigate to Tools | Go Tools | Go Fmt Project.

  • 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 Go | Imports.

Use goimports to automatically add missing and remove unused imports.

  • To apply goimports, navigate to Tools | Go Tools | Goimports File.

If goimports is not available in your project, click the go install goimports link in the notification. Alternatively, open the Terminal tool window (View | Tool Windows | Terminal) and run:

go install golang.org/x/tools/cmd/goimports@latest

go generate

Use the go generate command and the //go:generate directive to run code generation tools.

  1. Add a directive to your code:

    //go:generate command arguments

    For example: //go:generate stringer -type=Pill

  2. Run go generate from the IDE:

    • Tools | Go Tools | Go Generate File

    • Or use the gutter icon Run icon and select Go Generate

    Go Generate File

go vet

Use go vet to identify possible bugs and suspicious constructs in Go source files.

  • To run go vet, navigate to Tools | Go Tools | Go Vet File. The output will appear in the Terminal tool window.

Last modified: 03 April 2025