Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import local Go module in Goland IDE

What is proper way to import (use) go module internally?

For example:

creating a new module by: go mod init example.com/my-project (example.com or another domain, which doesn't exist)

and using it in the same project:

import (
    "example.com/my-project/package"
)

This sample was taken from Let's Go book (but extremely simplified)

The problem:

I am using Goland, and It doesn't recognize this local module. Goland advice me to use go get -t example.com/my-project/package command. But example.com/... just a name for a module

enter image description here

like image 434
Ali Mamedov Avatar asked May 13 '19 17:05

Ali Mamedov


People also ask

How do I import a package into GoLand?

To import a package, we use import syntax followed by the package name. 💡 Unlike other programming languages, a package name can also be a subpath like some-dir/greet and Go will automatically resolve the path to the greet package for us as you will see in the nested package topic ahead.

How do I enable Go module integration?

Enable Go modules in a projectPress Ctrl+Alt+S to open the IDE settings and select Go | Go Modules. Select the Enable Go modules integration checkbox. Click OK.


1 Answers

As @JimB mentioned, the problem related to Goland IDE. I found solution here.

Enabling Go modules (vgo) integration solves my problem.

enter image description here

like image 52
Ali Mamedov Avatar answered Sep 21 '22 19:09

Ali Mamedov