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 main module when resolving dependencies.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 main module when resolving dependencies.

A Guide to Familiarize Yourself With Workspaces in Go

2025/10/27 00:15
7 min read
For feedback or concerns regarding this content, please contact us at [email protected]

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 main 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.

\ The syntax of a go.work file is similar to a go.mod file and contains the following directives:

  • go: the go toolchain version e.g. go 1.18
  • use: adds a module on disk to the set of main modules in a workspace. Its argument is a relative path to the directory containing the module’s go.mod file. A use directive doesn’t add modules in subdirectories of the specified directory.
  • replace: Similar to a replace directive in a go.mod file, a replace directive in a go.work file replaces the contents of a specific version of a module, or all versions of a module, with contents found elsewhere.

Workflows

Workspaces are flexible and support a variety of workflows. The following sections are a brief overview of the ones we think will be the most common.

Add a feature to an upstream module and use it in your own module

  1. Create a directory for your workspace.

  2. Clone the upstream module you want to edit.

  3. Add your feature to the local version of the upstream module.

  4. Run go work init [path-to-upstream-mod-dir] in the workspace folder.

  5. Make changes to your own module in order to implement the feature added to the upstream module.

  6. Run go work use [path-to-your-module] in the workspace folder.

    The go work use command adds the path to your module to your go.work file:

go 1.18 use ( ./path-to-upstream-mod-dir ./path-to-your-module )

  1. Run and test your module using the new feature added to the upstream module.
  2. Publish the upstream module with the new feature.
  3. Publish your module using the new feature.

Work with multiple interdependent modules in the same repository

While working on multiple modules in the same repository, the go.work file defines the workspace instead of using replace directives in each module’s go.mod file.

  1. Create a directory for your workspace.

  2. Clone the repository with the modules you want to edit. The modules don’t have to be in your workspace folder as you specify the relative path to each with the use directive.

  3. Run go work init [path-to-module-one] [path-to-module-two] in your workspace directory.

    Example: You are working on example.com/x/tools/groundhog which depends on other packages in the example.com/x/tools module.

    \ You clone the repository and then run go work init tools tools/groundhog in your workspace folder.

    \ The contents of your go.work file resemble the following:

go 1.18 use ( ./tools ./tools/groundhog )

Any local changes made in the tools module will be used by tools/groundhog in your workspace.

Switching between dependency configurations

To test your modules with different dependency configurations you can either create multiple workspaces with separate go.work files, or keep one workspace and comment out the use directives you don’t want in a single go.work file.

\ To create multiple workspaces:

  1. Create separate directories for different dependency needs.
  2. Run go work init in each of your workspace directories.
  3. Add the dependencies you want within each directory via go work use [path-to-dependency].
  4. Run go run [path-to-your-module] in each workspace directory to use the dependencies specified by its go.work file.

\ To test out different dependencies within the same workspace, open the go.work file and add or comment out the desired dependencies.

Still using GOPATH?

Maybe using workspaces will change your mind. GOPATH users can resolve their dependencies using a go.work file located at the base of their GOPATH directory. Workspaces don’t aim to completely recreate all GOPATH workflows, but they can create a setup that shares some of the convenience of GOPATH while still providing the benefits of modules.

\ To create a workspace for GOPATH:

  1. Run go work init in the root of your GOPATH directory.
  2. To use a local module or specific version as a dependency in your workspace, run go work use [path-to-module].
  3. To replace existing dependencies in your modules’ go.mod files use go work replace [path-to-module].
  4. To add all the modules in your GOPATH or any directory, run go work use -r to recursively add directories 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.

\

Workspace commands

Along with go work init and go work use, Go 1.18 introduces the following commands for workspaces:

  • go work sync: pushes the dependencies in the go.work file back into the go.mod files of each workspace module.
  • go work edit: provides a command-line interface for editing go.work, for use primarily by tools or scripts.

\ Module-aware build commands and some go mod subcommands examine the GOWORK environment variable to determine if they are in a workspace context.

\ Workspace mode is enabled if the GOWORK variable names a path to a file that ends in .work. To determine which go.work file is being used, run go env GOWORK. The output is empty if the go command is not in workspace mode.

\ When workspace mode is enabled, the go.work file is parsed to determine the three parameters for workspace mode: A Go version, a list of directories, and a list of replacements.

\ Some commands to try in workspace mode (provided you already know what they do!):

go work init go work sync go work use go list go build go test go run go vet

Editor experience improvements

We’re particularly excited about the upgrades to Go’s language server gopls and the VSCode Go extension that make working with multiple modules in an LSP-compatible editor a smooth and rewarding experience.

\ Find references, code completion, and go to definitions work across modules within the workspace. Version 0.8.1 of gopls introduces diagnostics, completion, formatting, and hover for go.work files. You can take advantage of these gopls features with any LSP-compatible editor.

Editor specific notes

  • The latest vscode-go release allows quick access to your workspace’s go.work file via the Go status bar’s Quick Pick menu.

  • GoLand supports workspaces and has plans to add syntax highlighting and code completion for go.work files.

\ For more information on using gopls with different editors see the gopls documentation.

What’s next?

  • Download and install Go 1.18.
  • Try using workspaces with the Go workspaces Tutorial.
  • If you encounter any problems with workspaces, or want to suggest something, file an issue.
  • Read the workspace maintenance documentation.
  • Explore module commands for working outside of a single module including go work init, go work sync and more.

Beth Brown, for the Go team

\ This article is available on The Go Blog under a CC BY 4.0 DEED license.

\ Photo by Dylan Gillis on Unsplash

Disclaimer: The articles reposted on this site are sourced from public platforms and are provided for informational purposes only. They do not necessarily reflect the views of MEXC. All rights remain with the original authors. If you believe any content infringes on third-party rights, please contact [email protected] for removal. MEXC makes no guarantees regarding the accuracy, completeness, or timeliness of the content and is not responsible for any actions taken based on the information provided. The content does not constitute financial, legal, or other professional advice, nor should it be considered a recommendation or endorsement by MEXC.
Tags:

You May Also Like

Unprecedented Surge: Gold Price Hits Astounding New Record High

Unprecedented Surge: Gold Price Hits Astounding New Record High

BitcoinWorld Unprecedented Surge: Gold Price Hits Astounding New Record High While the world often buzzes with the latest movements in Bitcoin and altcoins, a traditional asset has quietly but powerfully commanded attention: gold. This week, the gold price has once again made headlines, touching an astounding new record high of $3,704 per ounce. This significant milestone reminds investors, both traditional and those deep in the crypto space, of gold’s enduring appeal as a store of value and a hedge against uncertainty. What’s Driving the Record Gold Price Surge? The recent ascent of the gold price to unprecedented levels is not a random event. Several powerful macroeconomic forces are converging, creating a perfect storm for the precious metal. Geopolitical Tensions: Escalating conflicts and global instability often drive investors towards safe-haven assets. Gold, with its long history of retaining value during crises, becomes a preferred choice. Inflation Concerns: Persistent inflation in major economies erodes the purchasing power of fiat currencies. Consequently, investors seek assets like gold that historically maintain their value against rising prices. Central Bank Policies: Many central banks globally are accumulating gold at a significant pace. This institutional demand provides a strong underlying support for the gold price. Furthermore, expectations around interest rate cuts in the future also make non-yielding assets like gold more attractive. These factors collectively paint a picture of a cautious market, where investors are looking for stability amidst a turbulent economic landscape. Understanding Gold’s Appeal in Today’s Market For centuries, gold has held a unique position in the financial world. Its latest record-breaking performance reinforces its status as a critical component of a diversified portfolio. Gold offers a tangible asset that is not subject to the same digital vulnerabilities or regulatory shifts that can impact cryptocurrencies. While digital assets offer exciting growth potential, gold provides a foundational stability that appeals to a broad spectrum of investors. Moreover, the finite supply of gold, much like Bitcoin’s capped supply, contributes to its perceived value. The current market environment, characterized by economic uncertainty and fluctuating currency values, only amplifies gold’s intrinsic benefits. It serves as a reliable hedge when other asset classes, including stocks and sometimes even crypto, face downward pressure. How Does This Record Gold Price Impact Investors? A soaring gold price naturally raises questions for investors. For those who already hold gold, this represents a significant validation of their investment strategy. For others, it might spark renewed interest in this ancient asset. Benefits for Investors: Portfolio Diversification: Gold often moves independently of other asset classes, offering crucial diversification benefits. Wealth Preservation: It acts as a robust store of value, protecting wealth against inflation and economic downturns. Liquidity: Gold markets are highly liquid, allowing for relatively easy buying and selling. Challenges and Considerations: Opportunity Cost: Investing in gold means capital is not allocated to potentially higher-growth assets like equities or certain cryptocurrencies. Volatility: While often seen as stable, gold prices can still experience significant fluctuations, as evidenced by its rapid ascent. Considering the current financial climate, understanding gold’s role can help refine your overall investment approach. Looking Ahead: The Future of the Gold Price What does the future hold for the gold price? While no one can predict market movements with absolute certainty, current trends and expert analyses offer some insights. Continued geopolitical instability and persistent inflationary pressures could sustain demand for gold. Furthermore, if global central banks continue their gold acquisition spree, this could provide a floor for prices. However, a significant easing of inflation or a de-escalation of global conflicts might reduce some of the immediate upward pressure. Investors should remain vigilant, observing global economic indicators and geopolitical developments closely. The ongoing dialogue between traditional finance and the emerging digital asset space also plays a role. As more investors become comfortable with both gold and cryptocurrencies, a nuanced understanding of how these assets complement each other will be crucial for navigating future market cycles. The recent surge in the gold price to a new record high of $3,704 per ounce underscores its enduring significance in the global financial landscape. It serves as a powerful reminder of gold’s role as a safe haven asset, a hedge against inflation, and a vital component for portfolio diversification. While digital assets continue to innovate and capture headlines, gold’s consistent performance during times of uncertainty highlights its timeless value. Whether you are a seasoned investor or new to the market, understanding the drivers behind gold’s ascent is crucial for making informed financial decisions in an ever-evolving world. Frequently Asked Questions (FAQs) Q1: What does a record-high gold price signify for the broader economy? A record-high gold price often indicates underlying economic uncertainty, inflation concerns, and geopolitical instability. Investors tend to flock to gold as a safe haven when they lose confidence in traditional currencies or other asset classes. Q2: How does gold compare to cryptocurrencies as a safe-haven asset? Both gold and some cryptocurrencies (like Bitcoin) are often considered safe havens. Gold has a centuries-long history of retaining value during crises, offering tangibility. Cryptocurrencies, while newer, offer decentralization and can be less susceptible to traditional financial system failures, but they also carry higher volatility and regulatory risks. Q3: Should I invest in gold now that its price is at a record high? Investing at a record high requires careful consideration. While the price might continue to climb due to ongoing market conditions, there’s also a risk of a correction. It’s crucial to assess your personal financial goals, risk tolerance, and consider diversifying your portfolio rather than putting all your capital into a single asset. Q4: What are the main factors that influence the gold price? The gold price is primarily influenced by global economic uncertainty, inflation rates, interest rate policies by central banks, the strength of the U.S. dollar, and geopolitical tensions. Demand from jewelers and industrial uses also play a role, but investment and central bank demand are often the biggest drivers. Q5: Is gold still a good hedge against inflation? Historically, gold has proven to be an effective hedge against inflation. When the purchasing power of fiat currencies declines, gold tends to hold its value or even increase, making it an attractive asset for preserving wealth during inflationary periods. To learn more about the latest crypto market trends, explore our article on key developments shaping Bitcoin’s price action. This post Unprecedented Surge: Gold Price Hits Astounding New Record High first appeared on BitcoinWorld.
Share
Coinstats2025/09/18 02:30
Top Trader Says One Day the XRP Chart Will Shock Everyone. Here’s why

Top Trader Says One Day the XRP Chart Will Shock Everyone. Here’s why

XRP continues to show strong momentum, attracting attention across the crypto market. A recent post by XRP Queen (@crypto_queen_x) included a chart projecting the
Share
Timestabloid2026/03/13 13:02
XRP on the Brink as Triangle Exhaustion Meets Volume Surge at South-Korea Exchanges ⋆ ZyCrypto

XRP on the Brink as Triangle Exhaustion Meets Volume Surge at South-Korea Exchanges ⋆ ZyCrypto

The post XRP on the Brink as Triangle Exhaustion Meets Volume Surge at South-Korea Exchanges ⋆ ZyCrypto appeared on BitcoinEthereumNews.com. Advertisement &nbsp
Share
BitcoinEthereumNews2026/03/13 12:56