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. Read more about Go modules at blog.golang.org.
Create a project with integration of Go modules (vgo)
Select
.In the New Project page, select Go modules (vgo).
In the Location field, specify the path where you want to store your project.
In the GOROOT field, specify the location of your Go installation. Usually, the location is defined automatically.
To change or install a new version of Go SDK, click the Add SDK button and select Local to choose the Go SDK version on your hard drive, or select Download to download Go SDK from the official repository. For more information about installing Go SDK, see Installing Go SDK.
From the Vgo Executable list, select the executable that you want to use with Go modules.
In the Proxy list, specify a value for the
GOPROXY
environment variable. You can select an option from the drop-down list (direct or off) or you can type your own value (for example,https://proxy.golang.org
).The direct value stands for a direct connection to the VCS (
GOPROXY=direct
). Also, you can use the empty value for a direct connection (GOPROXY=""
).The off value means that no network use is allowed.
(Optional) To use vendoring mode, select the Vendoring mode checkbox. For more information about vendoring, see Vendoring.
Click Create.
Working with Go modules
In the Project tool window ( ), Go modules are displayed with their full import path. The version of each Go Module is shown in a muted font color to help you distinguish between them.
Fetch dependencies with Go modules (vgo)
You can fetch a dependency with Go modules (vgo) if a project misses it.
Click the dependency declaration.
Press Alt+Enter and select Sync packages of <project_name>.
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.
Open Settings Ctrl+Alt+S and navigate to
.Select the Enable Go modules (vgo) integration checkbox and ensure that the Vgo Executable field points to a valid Project SDK directory.
Click OK.
Create a diagram of dependencies
Enable Go modules (vgo) in your project.
Right-click the go.mod file in your project and select .
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.
In settings Ctrl+Alt+S of the Go modules (vgo) project, navigate to Go | Go modules (vgo).
Select the Vendoring mode checkbox and click OK.
Navigate from a dependency import path to package source files
In the Project tool window ( ), double-click the
go.mod
file.Click a dependency import path and click
Ctrl+B.
Installing Go SDK
Select a local copy of the Go SDK
Ensure that the provided path to the folder with Go SDK includes bin and src folders.
In the New Project dialog, select Go modules (vgo).
Click the Add SDK button and select Local.
In the file browser, navigate to the SDK version that is on your hard drive.
Click Open.
Download the Go SDK
In the New Project dialog, select Go modules (vgo).
Click the Add SDK button select Download.
From the Version list, select the SDK version.
In the Location field, specify the path for the SDK. To use a file browser, click the Browse icon .
Click OK.