Can't use code defined in another file and I can not use installed packages
I'm using Go 1.16 and GoLand 2020.3.2 on Windows 10.
GOPATH = C:\Users\user\go
GOROOT = C:\Users\user\go\go1.16
I have two problems. The first is I can't use code defined in the same project but in a different file. For example, the following code will raise an error:
# command-line-arguments
.\main.go:9:13: undefined: otherFunc
project/a.go
package main
func main() {
otherFunc()
}
project/b.go
package main
func otherFunc() {
return true
}
I am under the impression that Go does not require me to import "b.go" into "a.go" and that "a.go" has access to all the functions defined in "b.go". Is this not the case or is there some configuration issue on my end?
Possibly related is the fact that I can not use any third party libraries installed from github.
If I type `import "github.com/julienschmidt/httprouter"`, GoLand will ask me to install the package. I click install and it does so successfully. The library is installed under `C:\Users\user\go\pkg\mod`. But GoLand looks for the package in `C:\Users\user\go\go1.16\src`.
What am I doing wrong?
请先登录再写评论。
Hi,
You encounter the issue with GO111MODULE=on variable by default, please see GO-10639.
As a workaround, please, create a go.mod file (go mod init) inside the current project or project with Go Modules on Welcome Screen.
By the way, you can install Toolbox App and GoLand Nightly build, which already includes the fix.
Regarding the issue with local import packages, please see my comment here.
I hope it helps.