Lazy package management

Is there a way to prevent go from trying to find a new non-standard import of a module online, and look under $GOPATH/pkg/mod, instead?

I am looking for a solution to working on multiple packages at once/not having to download dependencies every time I start a new project.

Related:
Semantics of the replace directive


disclaimer:
I think I get why this is not a best practice but, in the third world, the standard workflow is not always a viable option.

For this particular case, the Go 1.18 Workspaces could be what you are looking for.

In a nutshell, you can create a file that lists all modules you want to use locally, and if the main module (that is, the one that you run the go commands against) imports a module that is listed in the workspace file, the compiler fetches the replacement from the local module, rather than reaching out to the remote repository that the import path would point to.

The Workspace tutorial is a good starting point, or check out the Workspace maintenance section of the Go command documentation.

1 Like

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