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
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.
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.
As @JimB mentioned, the problem related to Goland IDE. I found solution here.
Enabling Go modules (vgo) integration solves my problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With