I\'ve been having a hard time trying to execute a simple golang program in a virtual machine powered by vagrant.
These are the relevant fields of my go env
:
The problem wasn't neither with GOROOT
nor GOPATH
. The go installation failed at some point, leaving the whole thing unstable ( files created but completely empty ). When provisioning the virtual machine again, the go module checked whether the files existed. As they did, it took by granted that the installation had already take place.
A clean up and fresh installation from scratch solved the problem.
A separate Go file in the same package,didn't have the "package main" declaration and because of this the console was giving errors on running the Main GO file.
On providing the package main declaration to the other Go file ,the error stopped showing.
This usually happens when you have a file e.g. foo_test.go empty or without package declaration.
With gopls (v0.4.0 at the time of writing, so pretty unstable!) and vscode doing cmd+shift+P > Go: Restart language server
worked for me.