package main
import (
"fmt"
type MyBoxItem struct {
Name string
type MyBox struct {
Items []MyBoxItem
func (box *MyBox) AddItem(item MyBoxItem) {
box.Items = append(box.Items, item)
func main() {
item1 := MyBoxItem{Name: "Test Item 1"}
item2 := MyBoxItem{Name: "Test Item 2"}
box := MyBox{}
box.AddItem(item1)
box.AddItem(item2)
// checking the output
fmt.Println(len(box.Items))
fmt.Println(box.Items)
box.AddItem(item1) and box.AddItem(item2) are marked red as an error. If I move my cursor above it it says (unresolved reference "AddItem"). Yet the code compiles and runs. And as this was the solution to an other stackoverflow question, I do not think that the code is wrong. Furthermore I cannot find any mistakes in it.
Can someone help? Thanks a lot
[EDIT: I load the code from a remote server and edit it locally on my private pc. After finishing my changes, I upload it to the remote server (using GoLands tools like "Browse remote host") and build and compile it there. After trying it out locally with the very same code, the error message sometimes is there and sometimes not. I am totally confused]
–
–
–
I'm using go module and it's solved by:
Deselect Preferences->Go->GOPATH->Use GOPATH that's defined in system environment
File->Invalidate caches / Restart
–
I cannot reproduce the issue in GoLand 2020.2. I suggest upgrading to it.
If that doesn't fix the issue then you can take the following steps to investigate the issue:
Is your project using Go modules or the traditional GOPATH?
If it's using GOPATH, have you enabled indexing of GOPATH under Settings/Preferences | Go | GOPATH?
If it's using Go modules, check to see that the support is enabled under Settings/Preferences | Go | Go Modules and then use Alt+Enter | Sync packages of <project>
–
–
–
I had the same problem and it got fix weirdly.So I installed and opened project in vscode in order to continue coding.It started installing a extension called gopls. After installation completed I returned to GoLand to close project, but I waited for indexing to complete.Suddenly references were green !
–
Today I faced that problem I fixed it to enable go module integration. For that
Settings -> Go -> Go modules then enable go modules integration.
This will work if you using go modules in your project.
Goland version 2020.1: I opened a folder with subfolders of golang projects and goland didn't recognize dependencies. I solved this problem setting Project GOPATH
ctrl + alt + s
Go > GOPATH
Click on plus button + In Project GOPATH
Add your golang's project folder, example: ~/projects/my-golang-projects
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.