I am new to Go and I have a question on packages. I have the following directory structure:
I am trying to import two different packages into main.go. Package1 which is in the same mod as main.go, imported successfully. However, the numbers package, which is an external package isn’t imported (when running main.go). My main.go:
Go 1.18+ even provides workspaces (via a go.work file) that help to keep the local replacement out of your repository.
And some additional background:
With Go Modules, GOPATH only manages the location of module cache and build artifacts. GOPATH is irrelevant for defining source code locations.
The most recent Go versions have GO111MODULE enabled by default. Hence no need to use that env var anymore.
Typically, the module path that you set inside go.mod points to a remote repository that go get, go mod download and similar commands can fetch the module from. For purely local development, you can ignore that rule, but if you intend to publish a module, consider using the final (remote) module path right from the start.