What are Go Workspaces?

Go 1.18 adds workspace mode to Go, which lets you work on multiple modules simultaneously.

Posted by Golang Workshop on Apr 8, 2022
Hey! If you love Go and building Go apps as much as I do, let's connect on Twitter or LinkedIn. I talk about this stuff all the time!

Go 1.18 adds workspace mode to Go, which lets you work on multiple modules simultaneously.

You can get Go 1.18 by visiting the download page. The release notes have more details about all the changes.

Workspaces

Workspaces in Go 1.18 let you work on multiple modules simultaneously without having to edit go.mod files for each module. Each module within a workspace is treated as a root module when resolving dependencies.

Previously, to add a feature to one module and use it in another module, you needed to either publish the changes to the first module, or edit the go.mod file of the dependent module with a replace directive for your local, unpublished module changes. In order to publish without errors, you had to remove the replace directive from the dependent module’s go.mod file after you published the local changes to the first module.

With Go workspaces, you control all your dependencies using a go.work file in the root of your workspace directory. The go.work file has use and replace directives that override the individual go.mod files, so there is no need to edit each go.mod file individually.

You create a workspace by running go work init with a list of module directories as space-separated arguments. The workspace doesn’t need to contain the modules you’re working with. The init command creates a go.work file that lists modules in the workspace. If you run go work init without arguments, the command creates an empty workspace.

To add modules to the workspace, run go work use moddir or manually edit the go.work file. Run go work use -r to recursively add directories in the argument directory with a go.mod file to your workspace. If a directory doesn’t have a go.mod file, or no longer exists, the use directive for that directory is removed from your go.work file.

Read more about it here

So what is a Go Workspace anyway?

Go workspaces

If you’re a developer, you’ve probably heard of golang. It’s a programming language that is growing in popularity, and for good reason. It’s simple to learn, yet powerful enough for complex applications. But what do you do if you want to start using golang? One option is to create your own workspace. In this blog post, we will discuss what Go Workspaces are and how they can help you get started with golang development!

If you’re a developer, you’ve probably heard of golang, or Go. It’s a programming language created by Google that has gained popularity in recent years for its simplicity and efficiency.

One of the unique features of Go is its use of workspaces. In this post, we’ll take a look at what Go workspaces are and how they can be used to improve your workflow.

A Go workspace is simply a directory that contains all the code for a particular project. This includes all the source code, as well as any binaries or executables that have been compiled from that source code.

The benefits of using a workspace are twofold. First, it allows you to keep your code organized in a way that makes sense for your project. Second, it enables youof golang. It’s a programming language that is growing in popularity, and for good reason. It’s simple to learn, yet powerful enough for complex applications. But what do you do if you want to start using golang? One option is to create your own workspace. In this blog post, we will discuss what Go Workspaces are and how they can help you get started with golang development!

Want to become an expert Go programmer?

Learn Go Programming

You can boost your skills in a couple of weekends by taking these high quality Go courses taught by top experts!

We have over 30 hours of Go courses you can take now! You can try it for 10 days free of charge.


Click here for a free trial!