Start with a Workspace for your Go Module Development

Start with a Workspace for your Go Module Development

When creating your Go projects, you may think it is required to host your modules on a source control service like GitHub. Or, that you need to publish your module to a remote repository before you can test or use it from a foreign module.

Fortunately, while using source control is good practice, it is not required to start your module development. Go uses the notion of Go Workspaces so that you can do all of your development locally untethered from a source control service. This is especially true early in your development process when you want to experiment with your code.

The Go Workspace

The workspace is a directory with a go.work file at its root. The file contains information that helps Go tools resolve modules that are hosted locally on your workstation.

For instance, the following is a go.work file that points to two local modules:

$> cat go.work 

go 1.22
use (
        ./emojis
        ./emoserv
)        

To setup a workspace, you use the go work init command (inside the workspace root directory) followed by the relative paths of valid Go modules that you want to include in your workspace:

go work init ./emojis ./emoserv        

You can modify the workspace to add or remove modules as needed. For instance, the following command removes module emojis:

go work edit -dropuse ./emojis        

Learn more

Learn more about the use of workspaces for Go module development in the LinkedIn course Programming with Go Modules.


要查看或添加评论,请登录

Vladimir Vivien的更多文章

社区洞察

其他会员也浏览了