How to make go search for packages in GOPATH while importing a package?

The code below shows that Go is only searching for packages in GOROOT. After not finding //package in GOROOT, ideally, it should look for packages in GOPATH, but it is not.

I have already set GOPATH to my workspace path which includes the folders: bin , src , and pkg .

$ go build main.go                                                           
main.go:5:2: package controller/userhandler is not in GOROOT (/usr/local/go/src/controller/userhandle

Depending on your version of go, the package controller/userhandler might be considered “stdlib”, as it does not contain something that looks like a hostname.

Also the fact whether you are in a go module might change a bit how packages are resolved.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.