GoLand 2024.3 Help

Go workspaces

Go workspaces help you to work with several modules in your project. When you create a go.work file, Go runs through the list of modules listed in the workspace, and creates a single list of dependencies. If go.mod files have replace directives, Go will also take them into account. A generated single dependency list is applied to all the modules listed in the workspace.

When you create a go.work file, GoLand automatically adds all the modules in the project.

Go workspaces

Create a workspace

  • Right-click the parent directory of your project and navigate to New | Go Workspace File.

    Create a workspace

Also, you can now generate go.work from go.mod if you have replace directives there.

Generate 'go.work' by using 'replace' directives

  • Place the caret at a replace directive, press Alt+Enter and select the Generate 'go.work' using 'replace' directives quick-fix.

    The underlying inspection that detects replace directives has the Warning severity and highlighting, meaning the relevant code is shown in a yellow box and the yellow warning triangle is shown in the top-right corner in the editor window.

    There may be no warning, however. If a generated workspace includes Go modules that are not replaced in the original go.mod, the warning is not shown due to possible side effects caused by migration.

    generate go.work using 'replace' directives

Merge several use directives into one directive

  • Click a use directive, press Alt+Enter, and select Merge multiple 'use' directives into one.

    Merge several use directives into one directive
Last modified: 11 October 2024