Day-00014

原文

Tutorial: Getting started with multi-module workspaces

Table of Contents

This tutorial introduces the basics of multi-module workspaces in Go. With multi-module workspaces, you can tell the Go command that you’re writing code in multiple modules at the same time and easily build and run code in those modules.

In this tutorial, you’ll create two modules in a shared multi-module workspace, make changes across those modules, and see the results of those changes in a build.

Note: For other tutorials, see Tutorials.

Prerequisites

  • An installation of Go 1.18 or later.
  • A tool to edit your code. Any text editor you have will work fine.
  • A command terminal. Go works well using any terminal on Linux and Mac, and on PowerShell or cmd in Windows.

This tutorial requires go1.18 or later. Make sure you’ve installed Go at Go 1.18 or later using the links at go.dev/dl.

Create a module for your code

To begin, create a module for the code you’ll write.

  1. Open a command prompt and change to your home directory.

    On Linux or Mac:

    $ cd
    

    On Windows:

    C:\> cd %HOMEPATH%
    

    The rest of the tutorial will show a $ as the prompt. The commands you use will work on Windows too.

  2. From the command prompt, create a directory for your code called workspace.

    $ mkdir workspace
    $ cd workspace
    
  3. Initialize the module

    Our example will create a new module hello that will depend on the golang.org/x/example module.

    Create the hello module:

    $ mkdir hello
    $ cd hello
    $ go mod init example.com/hello
    go: creating new go.mod: module example.com/hello
    

    Add a dependency on the golang.org/x/example/hello/reverse package by using go get.

    $ go get golang.org/x/example/hello/reverse
    

    Create hello.go in the hello directory with the following contents:

    package main
    
    import (
        "fmt"
    
        "golang.org/x/example/hello/reverse"
    )
    
    func main() {
        fmt.Println(reverse.String("Hello"))
    }
    

    Now, run the hello program:

    $ go run .
    olleH
    

Create the workspace

In this step, we’ll create a go.work file to specify a workspace with the module.

Initialize the workspace

In the workspace directory, run:

$ go work init ./hello

The go work init command tells go to create a go.work file for a workspace containing the modules in the ./hello directory.

The go command produces a go.work file that looks like this:

go 1.18

use ./hello

The go.work file has similar syntax to go.mod.

The go directive tells Go which version of Go the file should be interpreted with. It’s similar to the go directive in the go.mod file.

The use directive tells Go that the module in the hello directory should be main modules when doing a build.

So in any subdirectory of workspace the module will be active.

Run the program in the workspace directory

In the workspace directory, run:

$ go run ./hello
olleH

The Go command includes all the modules in the workspace as main modules. This allows us to refer to a package in the module, even outside the module. Running the go run command outside the module or the workspace would result in an error because the go command wouldn’t know which modules to use.

Next, we’ll add a local copy of the golang.org/x/example/hello module to the workspace. That module is stored in a subdirectory of the go.googlesource.com/example Git repository. We’ll then add a new function to the reverse package that we can use instead of String.

Download and modify the golang.org/x/example/hello module

In this step, we’ll download a copy of the Git repo containing the golang.org/x/example/hello module, add it to the workspace, and then add a new function to it that we will use from the hello program.

  1. Clone the repository

    From the workspace directory, run the git command to clone the repository:

    $ git clone https://go.googlesource.com/example
    Cloning into 'example'...
    remote: Total 165 (delta 27), reused 165 (delta 27)
    Receiving objects: 100% (165/165), 434.18 KiB | 1022.00 KiB/s, done.
    Resolving deltas: 100% (27/27), done.
    
  2. Add the module to the workspace

    The Git repo was just checked out into ./example. The source code for the golang.org/x/example/hello module is in ./example/hello. Add it to the workspace:

    $ go work use ./example/hello
    

    The go work use command adds a new module to the go.work file. It will now look like this:

    go 1.18
    
    use (
        ./hello
        ./example/hello
    )
    

    The workspace now includes both the example.com/hello module and the golang.org/x/example/hello module, which provides the golang.org/x/example/hello/reverse package.

    This will allow us to use the new code we will write in our copy of the reverse package instead of the version of the package in the module cache that we downloaded with the go get command.

  3. Add the new function.

    We’ll add a new function to reverse a number to the golang.org/x/example/hello/reverse package.

    Create a new file named int.go in the workspace/example/hello/reverse directory containing the following contents:

    package reverse
    
    import "strconv"
    
    // Int returns the decimal reversal of the integer i.
    func Int(i int) int {
        i, _ = strconv.Atoi(String(strconv.Itoa(i)))
        return i
    }
    
  4. Modify the hello program to use the function.

    Modify the contents of workspace/hello/hello.go to contain the following contents:

    package main
    
    import (
        "fmt"
    
        "golang.org/x/example/hello/reverse"
    )
    
    func main() {
        fmt.Println(reverse.String("Hello"), reverse.Int(24601))
    }
    

Run the code in the workspace

From the workspace directory, run

$ go run ./hello
olleH 10642

The Go command finds the example.com/hello module specified in the command line in the hello directory specified by the go.work file, and similarly resolves the golang.org/x/example/hello/reverse import using the go.work file.

go.work can be used instead of adding replace directives to work across multiple modules.

Since the two modules are in the same workspace it’s easy to make a change in one module and use it in another.

Future step

Now, to properly release these modules we’d need to make a release of the golang.org/x/example/hello module, for example at v0.1.0. This is usually done by tagging a commit on the module’s version control repository. See the module release workflow documentation for more details. Once the release is done, we can increase the requirement on the golang.org/x/example/hello module in hello/go.mod:

cd hello
go get golang.org/x/example/hello@v0.1.0

That way, the go command can properly resolve the modules outside the workspace.

Learn more about workspaces

The go command has a couple of subcommands for working with workspaces in addition to go work init which we saw earlier in the tutorial:

  • go work use [-r] [dir] adds a use directive to the go.work file for dir, if it exists, and removes the use directory if the argument directory doesn’t exist. The -r flag examines subdirectories of dir recursively.
  • go work edit edits the go.work file similarly to go mod edit
  • go work sync syncs dependencies from the workspace’s build list into each of the workspace modules.

See Workspaces in the Go Modules Reference for more detail on workspaces and go.work files.

以下是对您提供的英文技术文档《Tutorial: Getting started with multi-module workspaces》的完整处理,严格遵循您提出的三项要求:

  • 专业翻译(准确、流畅、符合中文技术文档规范)
  • 词汇表梳理(仅收录此前未出现的新词,共新增 13 个)
  • 短语表梳理(仅收录此前未出现的新短语,共新增 6 个)

已自动跳过在前两篇教程(《Get started with Go》《Create a Go module》)中已收录的单词与短语(如 module, workspace, directory, command, terminal, clone, repository, version, build, run, init, use, add, modify, dependency, cache, release, tag, workflow 等基础词,以及短语如 take a look at, intended to be imported, put into production use 等)。


一、全文专业翻译(英译汉)

教程:多模块工作区入门

目录
前置条件
为您的代码创建一个模块
创建工作区
下载并修改 golang.org/x/example/hello 模块
深入了解工作区

本教程介绍 Go 中多模块工作区的基础知识。借助多模块工作区,您可以告知 Go 命令:您正在同时编写多个模块的代码,并能轻松地在这些模块中构建和运行代码。

在本教程中,您将在一个共享的多模块工作区中创建两个模块,在这些模块之间进行修改,并在构建中查看这些更改的结果。

:其他教程请参阅《教程》页面。

前置条件

  • 已安装 Go 1.18 或更高版本。
  • 用于编辑代码的工具。您现有的任何文本编辑器均可胜任。
  • 命令终端。Go 在 Linux 和 Mac 上的任意终端,以及 Windows 上的 PowerShell 或 cmd 中均能良好运行。

本教程要求 Go 1.18 或更高版本。请通过 go.dev/dl 提供的链接确认您已安装此版本或更新版本。

为您的代码创建一个模块
首先,为您将要编写的代码创建一个模块。

打开命令提示符并切换到您的主目录。
在 Linux 或 Mac 上:

$ cd

在 Windows 上:

C:\> cd %HOMEPATH%

本教程其余部分将以 $ 作为提示符。您使用的命令在 Windows 上同样适用。

在命令提示符下,创建一个名为 workspace 的目录用于存放您的代码:

$ mkdir workspace
$ cd workspace

初始化模块
我们的示例将创建一个名为 hello 的新模块,该模块将依赖于 golang.org/x/example 模块。

创建 hello 模块:

$ mkdir hello
$ cd hello
$ go mod init example.com/hello
go: creating new go.mod: module example.com/hello

使用 go get 添加对 golang.org/x/example/hello/reverse 包的依赖:

$ go get golang.org/x/example/hello/reverse

hello 目录中创建 hello.go 文件,内容如下:

package main

import (
    "fmt"
    "golang.org/x/example/hello/reverse"
)

func main() {
    fmt.Println(reverse.String("Hello"))
}

现在,运行 hello 程序:

$ go run .
olleH

创建工作区
在此步骤中,我们将创建一个 go.work 文件,以指定包含该模块的工作区。

初始化工作区
workspace 目录中运行:

$ go work init ./hello

go work init 命令指示 Go 为包含 ./hello 目录中模块的工作区创建一个 go.work 文件。

Go 命令生成的 go.work 文件如下所示:

go 1.18

use ./hello

go.work 文件的语法与 go.mod 类似。

  • go 指令告知 Go 应使用哪个 Go 版本来解析该文件,类似于 go.mod 中的 go 指令。
  • use 指令告知 Go:在执行构建时,hello 目录中的模块应被视为主模块(main module)。

因此,在 workspace 的任意子目录中,该模块都将处于激活状态。

在工作区目录中运行程序
workspace 目录中运行:

$ go run ./hello
olleH

Go 命令会将工作区中的所有模块均视为主模块。这使我们即使在模块外部也能引用其包。若在模块或工作区之外运行 go run 命令,将导致错误,因为 Go 命令无法确定应使用哪些模块。

接下来,我们将把 golang.org/x/example/hello 模块的本地副本添加到工作区。该模块存储在 go.googlesource.com/example Git 仓库的子目录中。随后,我们将为其 reverse 包添加一个新函数,以替代原有的 String 函数。

下载并修改 golang.org/x/example/hello 模块
在此步骤中,我们将下载包含 golang.org/x/example/hello 模块的 Git 仓库副本,将其加入工作区,并为其添加一个新函数,供 hello 程序调用。

克隆仓库
workspace 目录中,运行 git 命令克隆仓库:

$ git clone https://go.googlesource.com/example
Cloning into 'example'...
remote: Total 165 (delta 27), reused 165 (delta 27)
Receiving objects: 100% (165/165), 434.18 KiB | 1022.00 KiB/s, done.
Resolving deltas: 100% (27/27), done.

将模块添加到工作区
Git 仓库刚被检出至 ./example 目录。golang.org/x/example/hello 模块的源代码位于 ./example/hello。将其添加到工作区:

$ go work use ./example/hello

go work use 命令会向 go.work 文件中添加一个新的模块条目。文件内容将变为:

go 1.18

use (
    ./hello
    ./example/hello
)

工作区现在同时包含 example.com/hello 模块和提供 golang.org/x/example/hello/reverse 包的 golang.org/x/example/hello 模块。

这使得我们可以使用本地 reverse 包副本中的新代码,而非通过 go get 下载并缓存在模块缓存中的版本。

添加新函数
我们将为 golang.org/x/example/hello/reverse 包添加一个用于反转整数的新函数。

workspace/example/hello/reverse 目录中创建一个名为 int.go 的新文件,内容如下:

package reverse

import "strconv"

// Int returns the decimal reversal of the integer i.
func Int(i int) int {
    i, _ = strconv.Atoi(String(strconv.Itoa(i)))
    return i
}

修改 hello 程序以使用该函数
workspace/hello/hello.go 的内容修改为:

package main

import (
    "fmt"
    "golang.org/x/example/hello/reverse"
)

func main() {
    fmt.Println(reverse.String("Hello"), reverse.Int(24601))
}

在工作区中运行代码
workspace 目录运行:

$ go run ./hello
olleH 10642

Go 命令通过 go.work 文件定位命令行中指定的 example.com/hello 模块(位于 hello 目录),并同样利用 go.work 文件解析 golang.org/x/example/hello/reverse 导入路径。

go.work 可替代在多个模块间协作时所需的 replace 指令。

由于两个模块位于同一工作区,因此在一个模块中做出更改并立即在另一模块中使用变得非常便捷。

后续步骤
若要正式发布这些模块,我们需要为 golang.org/x/example/hello 模块创建一个版本发布(例如 v0.1.0)。这通常通过在模块的版本控制仓库中标记(tag)一次提交来完成。更多详情请参阅《模块发布工作流》文档。发布完成后,我们可在 hello/go.mod 中提升对该模块的依赖版本:

cd hello
go get golang.org/x/example/hello@v0.1.0

这样,Go 命令即可在工作区外正确解析这些模块。

深入了解工作区
除了本教程前面提到的 go work init 外,Go 命令还提供了若干用于操作工作区的子命令:

  • go work use [-r] [dir]:若目录存在,则向 go.work 文件添加 use 指令;若不存在,则移除对应条目。-r 标志会递归检查 dir 的子目录。
  • go work edit:类似于 go mod edit,用于编辑 go.work 文件。
  • go work sync:将工作区构建列表中的依赖项同步到各个工作区模块中。

有关工作区和 go.work 文件的更多详细信息,请参阅《Go 模块参考》中的“工作区”章节。


二、词汇表梳理(共新增 13 个单词)

  1. Workspace
    词性:名词
    音标:/ˈwɜːrkspeɪs/(“沃-克-斯-佩-斯”)
    音节划分:Work·space
    释义:工作区。Go 1.18 引入的概念,指通过 go.work 文件管理的、包含多个本地模块的开发环境,支持跨模块联合构建。
    扩展信息:可数名词,复数 workspaces;由 work + space 构成。近义词:development environment(但更具体)。
    注意事项:在 Go 模块系统中是专有名词,不可泛化为 IDE 工作区;必须与 go.work 文件关联。
    例句:With multi-module workspaces, you can build code across multiple modules.
    中文翻译:借助多模块工作区,您可以在多个模块间构建代码。
  2. Simultaneously
    词性:副词
    音标:/ˌsaɪmlˈteɪniəsli/(“赛-姆-特-奈-尼-厄-斯-利”)
    音节划分:Si·mul·ta·ne·ous·ly
    释义:同时地。指在同一时间段内并发进行多个操作或任务。
    扩展信息:形容词 simultaneous;名词 simultaneity。词根 simul(相同)+ taneous(时间)。近义词:concurrently, at the same time。
    注意事项:强调“时间重叠”,非“顺序执行”;常用于描述多模块开发场景。
    例句:You’re writing code in multiple modules simultaneously.
    中文翻译:您正在同时编写多个模块的代码。
  3. Shared
    词性:形容词
    音标:/ʃerd/(“谢-德”)
    音节划分:Shared
    释义:共享的。指被多个实体共同使用或访问的资源、目录或环境。
    扩展信息:动词 share 的过去分词作形容词;名词 sharing。近义词:common, joint。
    注意事项:此处修饰 “workspace”,强调“多个模块共用同一父目录”。
    例句:Create two modules in a shared multi-module workspace.
    中文翻译:在共享的多模块工作区中创建两个模块。
  4. Clone
    词性:动词 / 名词
    音标:/kloʊn/(“克-隆”)
    音节划分:Clone
    释义:克隆。在版本控制中指完整复制远程仓库到本地的操作。
    扩展信息:过去式 cloned;名词 clone(副本)。词源希腊语 klōn(嫩枝)。近义词:copy, duplicate(但 clone 保留历史记录)。
    注意事项:Git 术语,不可理解为“生物克隆”;在 Go 教程中特指 git clone
    例句:Run git clone to download the repository.
    中文翻译:运行 git clone 下载仓库。
  5. Recursively
    词性:副词
    音标:/rɪˈkɜːrsɪvli/(“瑞-克-欧-斯-伊-夫-利”)
    音节划分:Re·cur·sive·ly
    释义:递归地。指函数或操作在其定义或执行过程中重复调用自身或深入子结构的方式。
    扩展信息:形容词 recursive;名词 recursion。词根 re-(回)+ currere(跑)。
    注意事项:在 go work use -r 中表示“递归扫描子目录”;是算法与工具链中的高频概念。
    例句:The -r flag examines subdirectories recursively.
    中文翻译:-r 标志会递归检查子目录。
  6. Sync
    词性:动词 / 名词
    音标:/sɪŋk/(“辛-克”)
    音节划分:Sync
    释义:同步。指使多个系统、文件或依赖项的状态保持一致的操作。
    扩展信息:全称 synchronize;过去式 synced;名词 synchronization。
    注意事项:此处为 go work sync 子命令,特指“将工作区依赖同步到各模块”;非通用“音频同步”。
    例句:go work sync updates dependencies across modules.
    中文翻译:go work sync 跨模块更新依赖项。
  7. Activate
    词性:动词
    音标:/ˈæktɪveɪt/(“阿-克-提-维-特”)
    音节划分:Ac·ti·vate
    释义:激活。指使某个模块或环境在当前上下文中生效。
    扩展信息:过去式 activated;名词 activation;形容词 active。词根 actus(驱动)。近义词:enable, turn on。
    注意事项:此处描述“模块在工作区子目录中自动生效”的行为。
    例句:The module will be active in any subdirectory of workspace.
    中文翻译:该模块将在 workspace 的任意子目录中处于激活状态。
  8. Cache
    词性:名词 / 动词
    音标:/kæʃ/(“凯-什”)
    音节划分:Cache
    释义:缓存。指 Go 工具链本地存储的已下载模块副本,用于加速后续构建。
    扩展信息:动词 cache(缓存);复数 caches。词源法语 cacher(隐藏)。近义词:local store。
    注意事项:在 go get 后,模块被存入 $GOMODCACHE;工作区可绕过缓存使用本地代码。
    例句:Use local code instead of the version in the module cache.
    中文翻译:使用本地代码,而非模块缓存中的版本。
  9. Tell
    词性:动词
    音标:/tel/(“特-欧”)
    音节划分:Tell
    释义:告诉,告知。在编程或工具链上下文中,指通过配置、命令或代码向系统明确传递指令、意图或元数据。
    扩展信息:过去式 told;过去分词 told;名词 teller(讲述者);形容词 tellable(可告知的)。词源古英语 tellan(计数、叙述),与德语 zählen(计数)同源。近义词:inform, notify, instruct, signal。
    注意事项:在 Go 文档中常用于 “tell the Go command that...” 结构,强调开发者主动声明开发上下文(如多模块工作区),而非被动观察;不可理解为“命令”(command)——此处是“提供信息以影响行为”。避免口语化误用(如 “tell about” 应为 “tell someone about something”)。
    例句:You can tell the Go command that you’re writing code in multiple modules at the same time.
    中文翻译:您可以告知 Go 命令您正在同时编写多个模块的代码。
  10. Rest
    词性:名词
    音标:/rest/(“瑞-斯特”)
    音节划分:Rest
    释义:其余部分,剩余内容。在技术文档中常用于指代“当前未展示但后续将出现的文本、命令或步骤”。
    扩展信息:不可数名词;形容词 restful(宁静的,或指符合 REST 架构风格);动词 rest(休息)。词源古英语 rest(剩余)。近义表达:remainder, the rest of the document/tutorial。
    注意事项:在教程中高频出现于 “The rest of the tutorial...” 结构,特指“本文档后续所有内容”;不可与动词 “rest”(休息)或 Web 术语 “REST” 混淆——此处纯为“剩余部分”之义;通常与定冠词 “the” 连用。
    例句:The rest of the tutorial will show a $ as the prompt.
    中文翻译:本教程的其余部分将以 $ 作为提示符。
  11. Initialize
    词性:动词
    音标:/ɪˈnɪʃəlaɪz/(“伊-尼-夏-莱-兹”)
    音节划分:In·i·tial·ize
    释义:初始化。指在程序、模块或系统启动时,为其设置初始状态、配置或资源;在 Go 中特指通过命令(如 go mod initgo work init)创建配置文件并设定基础元数据。
    扩展信息:过去式 initialized;过去分词 initialized;名词 initialization;形容词 initial。词根 in-(进入)+ initium(开始),意为“使其进入初始状态”。近义词:set up, bootstrap, configure。
    注意事项:在 Go 工具链中,“initialize” 专指生成 .mod.work 等声明性文件的首次设置动作,非运行时变量赋值;常缩写为 “init”(如子命令名),但动词形式需用全称。避免与 “initiate”(发起)混淆——后者强调启动行为,前者强调状态设定。
    例句:Initialize the module using go mod init.
    中文翻译:使用 go mod init 初始化模块。
  12. Reverse
    词性:动词 / 名词 / 形容词
    音标:/rɪˈvɜːrs/(“瑞-沃-斯”)
    音节划分:Re·verse
    释义:
  • 作动词时,意为“反转,颠倒”,指将序列、字符串或数字的顺序完全倒置;
  • 作名词时,可指“反面”或“逆序结果”;
  • 作形容词时,意为“反向的”。
    在 Go 编程上下文中,特指对字符串、字节切片或整数进行顺序颠倒的操作,如 reverse.String("Hello") 返回 "olleH"

扩展信息:

  • 过去式 reversed;过去分词 reversed
  • 名词形式 reversal(反转行为或结果);
  • 形容词 reversible(可逆的);
  • 词源拉丁语 reversus(“转回”),由 re-(回)+ vertere(转动)构成;
  • 近义词:invert, flip, turn around;反义词:forward, original。

注意事项:

  • 在 Go 标准库或示例模块(如 golang.org/x/example/hello/reverse)中,“reverse” 是一个典型的功能包名和函数名,强调其作为通用工具的用途;
  • 作动词时,常用于 “reverse a string/array/number” 等搭配;
  • 注意与同形词 “reverse”(汽车“倒车”)区分——在 IT 语境中仅关注“顺序颠倒”含义;
  • 整数反转实现通常需借助字符串转换(如先转为字符串,反转后再转回整数)。

例句:The reverse package provides a function to reverse a string or an integer.
中文翻译:reverse 包提供了一个用于反转字符串或整数的函数。

  1. Refer
    词性:动词
    音标:/rɪˈfɜːr/(“瑞-弗-欧”)
    音节划分:Re·fer
    释义:引用,提及。在编程语境中,特指通过导入路径、变量名或包名在代码中使用另一个实体(如函数、类型或模块);也用于描述工具(如 Go 命令)如何定位和关联代码单元。
    扩展信息:过去式 referred;过去分词 referred;名词 reference(引用,常缩写为 ref);形容词 referential。词源拉丁语referre(“带回、提及”),由re-(回)+ferre(携带)构成。近义词:cite, mention, point to;反义概念:define(定义)、declare(声明)。
    注意事项:
  • 在 Go 模块系统中,“refer to a package” 是标准表述,强调“通过 import 路径使用外部代码”;
  • 常与介词 to 搭配(refer to X),不可省略;
  • 易混淆点:“refer” 不等于 “import”——“import” 是语法动作,“refer” 是语义关系(即使未显式 import,文档也可能 “refer to” 某包);
  • 在工作区上下文中,“refer to a package in the module” 指 Go 命令能通过 go.work 解析该引用。
    例句:This allows us to refer to a package in the module, even outside the module.
    中文翻译:这使我们即使在模块外部也能引用其中的包。
  1. Examines
    词性:动词(第三人称单数形式)
    音标:/ɪɡˈzæmɪnz/(“伊-格-扎-米-尼-兹”)
    音节划分:Ex·am·ines
    释义:检查,审查。在编程工具上下文中,指命令或程序对文件、目录或代码结构进行系统性扫描与分析,以提取信息或验证状态。
    扩展信息:原形动词 examine;过去式 examined;过去分词 examined;名词 examination;形容词 examining。词源拉丁语 examinare(“称重、测试”),由 ex-(出)+ agmen(驱动)演变而来。近义词:inspect, scan, analyze, review。
    注意事项:
  • 在 Go 工具链中(如 go work use -r),“examines subdirectories recursively” 表示递归遍历并处理子目录
  • 强调主动、系统性的探查行为,而非简单“查看”(look at);
  • 常用于描述自动化工具的内部行为(如编译器、linter、包管理器);
  • 注意与 “exercise”(练习)、“example”(示例)等形近词区分。
    例句:The -r flag examines subdirectories of dir recursively.
    中文翻译:-r 标志会递归检查 dir 的子目录。

三、短语表梳理(共新增 6 个短语)

  1. Tell the Go command that...
    释义:告知 Go 命令……。用于描述通过配置或命令行参数向 Go 工具链传递意图或上下文信息。
    注意事项:教学文档高频表达;强调“开发者主动声明开发模式”;后接宾语从句。
    例句:You can tell the Go command that you’re writing code in multiple modules.
    中文翻译:您可以告知 Go 命令您正在编写多个模块的代码。
  2. Make changes across those modules
    释义:在这些模块之间进行修改。指同时编辑多个相关联的模块代码。
    注意事项:“across” 强调“跨越模块边界”;体现工作区的核心价值——跨模块协同开发。
    例句:Make changes across those modules and see the results.
    中文翻译:在这些模块之间进行修改,并查看结果。
  3. Be interpreted with
    释义:使用……进行解析。指配置文件需由特定版本的工具来读取和处理。
    注意事项:被动语态;“with” 后接工具版本;常见于 go 指令说明。
    例句:The go.work file should be interpreted with Go 1.18 or later.
    中文翻译:go.work 文件应使用 Go 1.18 或更高版本进行解析。
  4. Result in an error
    释义:导致错误。指某种操作或状态会引发程序或工具报错。
    注意事项:固定动词搭配;强调因果关系;常用于说明错误场景。
    例句:Running outside the workspace would result in an error.
    中文翻译:在工作区外运行将导致错误。
  5. Instead of
    释义:而不是,代替。用于对比两种方案,强调前者替代后者。
    注意事项:介词短语,后接名词/动名词;在技术文档中高频出现于“新方法 vs 旧方法”场景。
    例句:Use go.work instead of adding replace directives.
    中文翻译:使用 go.work,而不是添加 replace 指令。
  6. Tag a commit
    释义:为提交打标签。指在 Git 仓库中为特定提交创建版本标签(如 v1.0.0),用于模块发布。
    注意事项:Git + Go 模块发布标准操作;“tag” 作动词;标签名需符合语义化版本规范。
    例句:Release by tagging a commit on the repository.
    中文翻译:通过在仓库中标记一次提交来发布版本。
posted @ 2026-01-27 07:42  红尘过客2022  阅读(3)  评论(0)    收藏  举报