GoLand 2019.3 Help

Integration with Go tools

Format Go code with gofmt

With gofmt, you can format Go source code in the opened file or in the whole Go project.

  1. To format code in the opened file, go to Tools | Go Tools | Go fmt file.

  2. To format code in the current project, go to Tools | Go Tools | Go fmt project.

  3. To format code before you commit your changes into VCS, select the Go fmt checkbox. For more information about committing your changes, see Commit and push changes.

    Example of the go fmt tool

Add import lines automatically with goimports

With goimports, you can automatically update your Go import lines (add missing and remove unreferenced imports).

  1. If your project does not have goimports, click the go get goimports link in the Goimports file notification window. Otherwise, open the Terminal tool window (View | Tool Windows | Terminal), and type the following command to install goimports: go get golang.org/x/tools/cmd/goimports. Press Enter.

  2. To add missing imports, navigate to Tools | Go Tools and click Goimports file.

Example of goimports

Create or update Go source files with go generate

  1. Add the following line to your Go code: //go:generate command arguments (for example, //go:generate stringer -type=Pill)

  2. Click Tools | Go Tools | Go generate file.

    Example of go generate

Inspect Go code with go vet

  • To find possible bugs or suspicious constructs with go vet, click Tools | Go Tools | Go vet file. You can see the result of code analysis in the Terminal tool window.

    Example of go vet
Last modified: 23 March 2020