VSCode Go Plugin : GOPATH vs GOMODCACHE

2.5k Views Asked by At

I use a custom location for GOMODCACHE (~/.gomodcache/) and GOPATH ~/project/go. This is to handle the errors from GOPLS while using the mono-repo approach of workspace.

When I do go get, the modules are downloaded to GOMODCACHE but, unable to see them in GOPATH. I use VSCode’s Go plugin. The plugin just looks for the list of modules from GOPATH and GOROOT. So, the plugin is unable to find the modules from GOMODCACHE and unable to provide suggestions on autocomplete.

Is there a way to get the modules into GOPATH instead of GOMODCACHE? Or Is there a way to make vscode to read the modules from GOMODCACHE instead of GOPATH?

2

There are 2 best solutions below

0
RamaV On

It worked for me with the below steps :

  1. run go mod init for main.go which will generate go.mod file
  2. run go get for required packages which will generate go.sum
1
raaa On

Here is the answer: https://levelup.gitconnected.com/using-modules-and-packages-in-go-36a418960556 You should try to play with GO111MODULE env variable. In the article everything is written.

With GO111MODULE=on you use go install gthub.com/blabla/ and it installs mods in GOPATH/pkg/mod.

With GO111MODULE=off you use go get github.com/blabla and it puts mods in GOPATH/src directory.