Working on multiple modules – workspaces
Sometimes you need to work with multiple interdependent modules. A convenient way to do this is by defining a workspace. A workspace is simply a set of modules. If one of the modules within a workspace refers to a package in another module in the same workspace, it is resolved locally instead of that module being downloaded over the network.
How to do it...
- To create a workspace, you have to have a parent directory containing all your work modules:
$ cd ~/projects $ mkdir ws $ cd ws
- Then, start a workspace using this:
$ go work init
This will create a
go.work
file in this directory. - Place the module you are working on into this directory.
Let’s demonstrate this using our example. Let’s say we have the following directory structure:
$HOME/ projects/ ws/ go.work webform sqlite
Now, we want to add the two modules,
webform
andsqlite
, to the workspace. To do that, use this:$ go work use ./webform $ go work use ./sqlite
These commands will add the two modules to your workspace. Any
sqlite
reference from thewebform
module will now be resolved to use the local copy of the module.