# Go 工作区

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/zh-cn/help/idea/llms.txt).

> **TL;DR**
> 需要 Go 1.18 或更高版本。

Go 工作区使用  `go.work`  文件在一个项目中使用多个模块。 该文件会列出 Go 在解析依赖项时视为主模块的模块。

当您创建一个  `go.work`  文件时，IntelliJ IDEA 会自动包含当前项目中的所有模块。

Procedure: 创建工作空间

* 右键点击您的项目的父目录。 然后选择  `新建 | Go Workspace 文件` 。

Procedure: 将本地替换模块添加到工作区

* 在包含项目中模块的相对  `替换`  指令的  `go.mod`  文件中，将文本光标置于某个指令处，按 `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Alt+Enter` (NetBeans), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS))，然后选择   将所有本地替换的模块添加到工作区  。

如果不存在工作区，IntelliJ IDEA 会创建一个  `go.work`  文件，其中包含主模块及其本地替换项。 否则，会将替换项添加到现有工作区。

Procedure: 将多个 use 指令合并为一个指令

* 点击  `use` 指令，按 `Alt+Enter` (Windows), `⌥ ⏎` (macOS), `⌥ ⏎` (IntelliJ IDEA Classic (macOS)), `⌥ ⏎` (macOS System Shortcuts), `Alt+Enter` (XWin), `Alt+Enter` (GNOME), `Alt+Enter` (KDE), `Alt+Enter` (Emacs), `Alt+Enter` (Sublime Text), `⌥ ⏎` (Sublime Text (macOS)), `Alt+Enter` (Visual Studio), `⌥ ⏎` (Visual Studio (macOS)), `Alt+Enter` (NetBeans), `Ctrl+1` (Eclipse), `⌘ 1` (Eclipse (macOS))，然后选择   将多个“use”指令合并为一个  。

