The reason why this is happening is because we're mixing relative and remote imports. In main.go, the
globalvar package is imported as
./globalvar but usevar/usevar.go imports it as
github.com/Denton-L/gotest/globalvar. Therefore, Go considers these to be separate packages with their own namespaces and thus, they have their own separate global variables that happen to be named identically.
In order to solve this, change the relative import to be a remote import, so the main.go import statement should look like this:
import ( "fmt" "github.com/Denton-L/gotest/globalvar" "github.com/Denton-L/gotest/usevar" )
This will let the compiler know that they are actually the same package and, thus, the global variable will be shared.