GoLand 2019.2 Help

Creating a project with Go modules (vgo)

The go get command downloads the latest version of dependencies from the master branch of the Go repository. In some cases, this approach does not work. For example, when you have two projects that depend on different versions of a third-party library. With Go modules (formerly known as vgo), you can download and import the necessary library versions per project.

Create a project with integration of Go modules (vgo)

  1. Install the Go SDK. In GoLand, you can navigate to your local SDK copy or download the Go SDK from the Internet.

  2. Select File | New | Project.

  3. In the New Project page, select Go modules (vgo).

  4. Ensure that the project uses correct file paths and click OK.

Integration with Go modules (vgo)

Fetch dependencies with Go modules (vgo)

You can fetch a dependency with Go modules (vgo) if a project misses it.

  1. Click the dependency declaration.

  2. Press Alt+Enter and select Sync packages of <project_name>.

Fetch a source with Go modules (vgo)

Enable Go modules (vgo) in a project

A new Go modules project already has Go modules (vgo) enabled. If you pulled your Go modules (vgo) project from Github, you need to enable %project_=type% manually.

  1. Open Settings Ctrl+Alt+S and navigate to Go | Go modules.

  2. Select the Enable Go modules (vgo) integration checkbox and ensure that the Vgo Executable field points to a valid Project SDK directory.

  3. Click OK.

Enable Go modules (vgo) in a project

Create a diagram of dependencies

  1. Enable Go modules (vgo) in your project.

  2. Right-click the go.mod file in your project and select Diagrams | Show Diagram.

Enable the vendoring mode

With the vendoring mode enabled, you build your application only with dependency packages that are stored inside your project under the vendor directory. In this mode, Go commands ignore dependency descriptions in go.mod and assume that the vendor directory holds the correct copies of dependencies. By default, when you use Go modules, the vendor directory is ignored during the build.

  1. In settings Ctrl+Alt+S of the Go modules (vgo) project, navigate to Go | Go modules (vgo).

  2. Select the Vendoring mode checkbox and click OK.

Enable the vendoring mode

Select a local copy of the Go SDK

Ensure that the provided path to the folder with Go SDK includes bin и src folders.

  1. In the New Project dialog, select Go modules (vgo).

  2. Click the Add SDK icon the Add SDK icon near the GOROOT field and select Local.

  3. In the file browser, navigate to the SDK version that is on your hard drive.

  4. Click Open.

Navigate to a local copy of Go SDK

Download the Go SDK

  1. In the New Project dialog, select Go modules (vgo).

  2. Click the Add SDK icon (the Add SDK icon) near the GOROOT field and select Download.

  3. From the Version list, select the SDK version.

  4. In the Target directory field, specify the path for the SDK. To use a file browser, click the Browse icon the Browse icon.

  5. Click OK.

Download the Go SDK
Last modified: 29 October 2019