Home > Mobile >  Golang issue in vs code while accessing private repo
Golang issue in vs code while accessing private repo

Time:10-18

I have a Golang project and the version I am using is 1.13. And my module is hosted in my private repo. And my repo starts with:

module <Private-Repo>-service

go 1.13

And there are some Repos that are from Github and go packages. I am using Golang's vs code package

Go Team at Google

I have my env like:

GOROOT="/usr/local/go"
GOPATH="/home/{User}/go"
GOPRIVATE=<Private-Repo-URL>

And my folder where I am copying my Repo is inside /home/{User}/go/src/

But I am unable to fix the issue and it is saying:

could not import github.com/golang/mock/gomock (cannot find package "github.com/golang/mock/gomock" in any of 
    /usr/local/go/src/github.com/golang/mock/gomock (from $GOROOT)
    /home/{User}/go/src/github.com/golang/mock/gomock (from $GOPATH))compilerBrokenImport

So I need to fix this issue in the visual studio code.

CodePudding user response:

Try first if the issue persists:

  • in command-line (go get github.com/golang/mock/gomock, in the root folder of your project, where go.mod/go.sum are)
  • after upgrading, if possible, to go 1.17.

Once a go build is working in command-line, you can switch back to VSCode, and confirm it is also fine there.

CodePudding user response:

Instead of storing your code directly inside your $GOPATH, try to store it inside another directory namely github.com/{github-username}/.

From:

/home/{User}/go/src/

To:

/home/{User}/go/src/github.com/{github-username}/
  • Related