Reputation: 111
I'm trying through kubebuilder tutorial, and just imported existing project to GoLand.
Workthrough with kubebuilder auto-generated scaffold codes, and auto-downloaded pkgs with go mod for me. I had no problem when I was working with commandline environment, but turns out, after opening the project with GoLand, IDE is failing to resolve imported package names, which means it is failing to detect - or link - packages installed by go mod.
I enabled go mod(with vendoring) and dep both from IDE preferences, set GOPATH and Go runtime properly, but the error keeps to appear.
I don't know why I'm getting this error, and how to solve it.
+) Working Directory is $GOPATH/src/example, all the logics and settings are placed in the directory. Installed dependencies are placed under $GOPATH/pkg/mod.
Upvotes: 3
Views: 9240
Reputation: 871
Is Go modules integration enabled via File | Settings | Languages & Frameworks | Go | Go Modules
Upvotes: -1
Reputation: 7477
I enabled go mod(with vendoring) and dep both from IDE preferences, set GOPATH and GOROOT properly, but the error keeps to appear.
Let's assume that you have the following setup on your machine:
/usr/lib/go
/home/florin/go
demobuilder
is created under /home/florin/projects/demobuilder
. I recommend this as opposed to using GOPATH, as you do, for Go Modules projects because they behave in a different way while in GOPATH.First, make sure that you have GoLand 2019.3.1 or newer.
Then, after creating the demobuilder
project, start GoLand, then click on the Open Project
button.
When the project is opened, if you have not configured yet, the IDE will ask you for the Go SDK configuration, aka GOROOT. It will be a yellow bar at the top of the editor. Click on the link on the right side to configure it. You can select the local installation and point it to /usr/local/go
. If you don't have Go installed, you can also download it in a directory of your choice.
Then, the IDE should automatically notice that the project is a Go Modules based project and enable the support for them. If it's not, then go to Settings/Preferences | Go | Go Modules
and enable that. DO NOT enable both Go Modules and dep support at the same time. If you did that, disable the dep integration and try again.
You can see all of these in the help page.
Upvotes: 6