原文
Tutorial: Create a Go module
Table of Contents
-
Prerequisites
-
Start a module that others can use
This is the first part of a tutorial that introduces a few fundamental features of the Go language. If you're just getting started with Go, be sure to take a look at Tutorial: Get started with Go, which introduces the go command, Go modules, and very simple Go code.
In this tutorial you'll create two modules. The first is a library which is intended to be imported by other libraries or applications. The second is a caller application which will use the first.
This tutorial's sequence includes seven brief topics that each illustrate a different part of the language.
- Create a module -- Write a small module with functions you can call from another module.
- Call your code from another module -- Import and use your new module.
- Return and handle an error -- Add simple error handling.
- Return a random greeting -- Handle data in slices (Go's dynamically-sized arrays).
- Return greetings for multiple people -- Store key/value pairs in a map.
- Add a test -- Use Go's built-in unit testing features to test your code.
- Compile and install the application -- Compile and install your code locally.
Note: For other tutorials, see Tutorials.
Prerequisites¶
- Some programming experience. The code here is pretty simple, but it helps to know something about functions, loops, and arrays.
- A tool to edit your code. Any text editor you have will work fine. Most text editors have good support for Go. The most popular are VSCode (free), GoLand (paid), and Vim (free).
- A command terminal. Go works well using any terminal on Linux and Mac, and on PowerShell or cmd in Windows.
Start a module that others can use¶
Start by creating a Go module. In a module, you collect one or more related packages for a discrete and useful set of functions. For example, you might create a module with packages that have functions for doing financial analysis so that others writing financial applications can use your work. For more about developing modules, see Developing and publishing modules.
Go code is grouped into packages, and packages are grouped into modules. Your module specifies dependencies needed to run your code, including the Go version and the set of other modules it requires.
As you add or improve functionality in your module, you publish new versions of the module. Developers writing code that calls functions in your module can import the module's updated packages and test with the new version before putting it into production use.
-
Open a command prompt and
cdto your home directory.On Linux or Mac:
cdOn Windows:
cd %HOMEPATH% -
Create a
greetingsdirectory for your Go module source code.For example, from your home directory use the following commands:
mkdir greetings cd greetings -
Start your module using the
go mod initcommand.Run the
go mod initcommand, giving it your module path -- here, useexample.com/greetings. If you publish a module, this must be a path from which your module can be downloaded by Go tools. That would be your code's repository.For more on naming your module with a module path, see Managing dependencies.
$ go mod init example.com/greetings go: creating new go.mod: module example.com/greetingsThe
go mod initcommand creates a go.mod file to track your code's dependencies. So far, the file includes only the name of your module and the Go version your code supports. But as you add dependencies, the go.mod file will list the versions your code depends on. This keeps builds reproducible and gives you direct control over which module versions to use. -
In your text editor, create a file in which to write your code and call it greetings.go.
-
Paste the following code into your greetings.go file and save the file.
package greetingsimport "fmt"// Hello returns a greeting for the named person. func Hello(name string) string {// Return a greeting that embeds the name in a message.message := fmt.Sprintf("Hi, %v. Welcome!", name)return message }This is the first code for your module. It returns a greeting to any caller that asks for one. You'll write code that calls this function in the next step.
In this code, you:
-
Declare a
greetingspackage to collect related functions. -
Implement a
Hellofunction to return the greeting.This function takes a
nameparameter whose type isstring. The function also returns astring. In Go, a function whose name starts with a capital letter can be called by a function not in the same package. This is known in Go as an exported name. For more about exported names, see Exported names in the Go tour. -
Declare a
messagevariable to hold your greeting.In Go, the
:=operator is a shortcut for declaring and initializing a variable in one line (Go uses the value on the right to determine the variable's type). Taking the long way, you might have written this as:var message string message = fmt.Sprintf("Hi, %v. Welcome!", name) -
Use the
fmtpackage'sSprintffunction to create a greeting message. The first argument is a format string, andSprintfsubstitutes thenameparameter's value for the%vformat verb. Inserting the value of thenameparameter completes the greeting text. -
Return the formatted greeting text to the caller.
-
In the next step, you'll call this function from another module.
以下是对您提供的英文技术文档《Tutorial: Create a Go module》的完整处理,严格遵循您提出的三项要求:专业翻译、词汇表梳理、短语表梳理。
已自动跳过此前在《Get started with Go》教程中已收录的单词与短语(如 experience, directory, track, actual, purpose, section, improve, quote, highlighted, requirement, sum, authenticating, discovery, support, typically, as well as, For more, For example, Along the way, For the purposes of this tutorial, Don't communicate by sharing memory..., Take a look at 等)。
一、全文专业翻译(英译汉)
教程:创建一个 Go 模块
目录
前置条件
创建一个可供他人使用的模块
本教程是介绍 Go 语言若干基础特性的第一部分。如果您刚刚开始接触 Go,请务必先阅读《Go 语言入门》教程,该教程介绍了 go 命令、Go 模块以及非常简单的 Go 代码。
在本教程中,您将创建两个模块。第一个是一个库,旨在被其他库或应用程序导入使用;第二个是一个调用方应用程序,将使用第一个模块。
本教程包含七个简短的主题,每个主题分别演示语言的不同特性:
- 创建模块 —— 编写一个小型模块,其函数可被另一模块调用。
- 从另一模块调用您的代码 —— 导入并使用您新建的模块。
- 返回并处理错误 —— 添加简单的错误处理机制。
- 返回随机问候语 —— 在切片(Go 的动态数组)中处理数据。
- 为多人返回问候语 —— 在映射(map)中存储键值对。
- 添加测试 —— 使用 Go 内置的单元测试功能测试您的代码。
- 编译并安装应用程序 —— 在本地编译并安装您的代码。
注:其他教程请参阅《教程》页面。
前置条件
具备一定的编程经验。本文中的代码相当简单,但了解函数、循环和数组的相关知识会有所帮助。
用于编辑代码的工具。您手头的任何文本编辑器均可胜任。大多数文本编辑器对 Go 有良好的支持,其中最流行的包括 VSCode(免费)、GoLand(付费)和 Vim(免费)。
命令终端。Go 在 Linux 和 Mac 上的任意终端,以及 Windows 上的 PowerShell 或 cmd 中均能良好运行。
创建一个可供他人使用的模块
首先创建一个 Go 模块。在模块中,您可以将一个或多个相关包组织在一起,以提供一组独立且有用的功能。例如,您可以创建一个包含金融分析函数的模块,供编写金融类应用程序的开发者使用。有关模块开发的更多信息,请参阅《开发与发布模块》。
Go 代码被划分为包(package),而包又被组织到模块(module)中。您的模块会明确声明运行代码所需的依赖项,包括所支持的 Go 版本以及其他必需的模块集合。
当您向模块中添加新功能或改进现有功能时,可以发布该模块的新版本。调用您模块中函数的开发者可以导入更新后的包,并在将其投入生产环境前,先用新版本进行测试。
打开命令提示符,并切换到您的主目录。
在 Linux 或 Mac 上:
cd
在 Windows 上:
cd %HOMEPATH%
为您的 Go 模块源代码创建一个名为 greetings 的目录。
例如,从主目录执行以下命令:
mkdir greetings
cd greetings
使用 go mod init 命令初始化您的模块。
运行 go mod init 命令,并指定您的模块路径——此处使用 example.com/greetings。如果您计划发布此模块,则该路径必须是 Go 工具能够从中下载模块的位置,通常即为您的代码仓库地址。
关于使用模块路径命名模块的更多内容,请参阅《依赖管理》。
$ go mod init example.com/greetings
go: creating new go.mod: module example.com/greetings
go mod init 命令会创建一个 go.mod 文件,用于跟踪您代码的依赖项。目前,该文件仅包含模块名称及代码所支持的 Go 版本。但随着您添加依赖项,go.mod 文件将列出代码所依赖的具体模块版本。这确保了构建的可重现性,并使您能够直接控制所使用的模块版本。
在文本编辑器中创建一个文件用于编写代码,并将其命名为 greetings.go。
将以下代码粘贴到 greetings.go 文件中并保存:
package greetingsimport "fmt"// Hello returns a greeting for the named person.
func Hello(name string) string {// Return a greeting that embeds the name in a message.message := fmt.Sprintf("Hi, %v. Welcome!", name)return message
}
这是您模块的第一段代码,它会向任何请求者返回一条问候语。下一步,您将编写调用此函数的代码。
在此代码中,您完成了以下操作:
-
声明了一个
greetings包,用于收集相关函数。 -
实现了一个
Hello函数以返回问候语。
该函数接收一个类型为string的name参数,并返回一个string。在 Go 中,函数名以大写字母开头时,可被其他包中的函数调用。这在 Go 中被称为“导出名”(exported name)。有关导出名的更多信息,请参阅 Go 语言之旅中的《导出名》章节。 -
声明了一个
message变量用于保存问候语。
在 Go 中,:=运算符是声明并初始化变量的快捷方式(Go 会根据右侧的值推断变量类型)。若采用更显式的方式,您可能会这样写:var message string message = fmt.Sprintf("Hi, %v. Welcome!", name) -
使用
fmt包的Sprintf函数创建问候消息。第一个参数是格式字符串,Sprintf会将name参数的值代入%v格式动词处。插入name参数的值后,即完成问候文本的构建。 -
将格式化后的问候文本返回给调用方。
在下一步中,您将从另一个模块调用此函数。
二、词汇表梳理(共新增 12 个单词)
- Fundamental
词性:形容词
音标:/ˌfʌndəˈmentl/(“范-德-门-特-欧”)
音节划分:Fun·da·men·tal
释义:基础的,根本的。指构成某系统或知识体系核心的、不可或缺的要素。
扩展信息:名词形式 fundamental(基本原理,常作复数 fundamentals);副词 fundamentally。词根 fundamentum(拉丁语“地基”)。近义词:basic, essential, core。
注意事项:在技术文档中常修饰 “features”, “concepts”, “principles”,强调不可省略的基础性。
例句:This tutorial introduces a few fundamental features of the Go language.
中文翻译:本教程介绍了 Go 语言的若干基础特性。 - Caller
词性:名词
音标:/ˈkɔːlər/(“考-勒”)
音节划分:Call·er
释义:调用方。在编程中指发起函数或方法调用的代码实体(如另一个函数、模块或应用程序)。
扩展信息:动词 call 的施事者名词;反义概念 callee(被调用方)。
注意事项:在 Go 文档中常与 “application” 或 “module” 搭配,如 “caller application”。
例句:The second is a caller application which will use the first.
中文翻译:第二个是一个调用方应用程序,将使用第一个模块。 - Sequence
词性:名词
音标:/ˈsiːkwəns/(“西-克-温-斯”)
音节划分:Se·quence
释义:序列,顺序。指按特定逻辑或时间排列的一系列步骤或项目。
扩展信息:动词 sequence(排序);形容词 sequential。词根 sequi(跟随)。近义词:series, order。
注意事项:在教程上下文中指“教学步骤的有序安排”,非数学序列。
例句:This tutorial's sequence includes seven brief topics.
中文翻译:本教程的序列包含七个简短的主题。 - Illustrate
词性:动词
音标:/ˈɪləstreɪt/(“伊-乐-斯特-雷-特”)
音节划分:Il·lus·trate
释义:说明,阐明。通过示例、图示或代码展示某个概念或特性。
扩展信息:过去式 illustrated;名词 illustration;形容词 illustrative。词根 illustrare(照亮、阐明)。近义词:demonstrate, explain, exemplify。
注意事项:技术文档高频动词,强调“通过实例使抽象概念具体化”。
例句:Each topic illustrates a different part of the language.
中文翻译:每个主题都阐明了语言的不同部分。 - Financial
词性:形容词
音标:/faɪˈnænʃl/(“法-伊-南-夏-欧”)
音节划分:Fi·nan·cial
释义:金融的,财务的。与资金管理、投资、会计等经济活动相关的。
扩展信息:名词 finance;副词 financially。
注意事项:此处作为领域示例(financial analysis/applications),体现模块的行业应用场景。
例句:You might create a module for doing financial analysis.
中文翻译:您可以创建一个用于金融分析的模块。 - Specify
词性:动词
音标:/ˈspesɪfaɪ/(“斯-佩-斯-艾-法-伊”)
音节划分:Spec·i·fy
释义:明确说明,指定。在配置或声明中精确指出某项要求或属性。
扩展信息:过去式 specified;名词 specification(规格,常缩写为 spec)。词根 species(种类)+ facere(做)。近义词:define, declare, state。
注意事项:在依赖管理语境中,指“在 go.mod 中声明依赖项”。
例句:Your module specifies dependencies needed to run your code.
中文翻译:您的模块会明确说明运行代码所需的依赖项。 - Publish
词性:动词
音标:/ˈpʌblɪʃ/(“帕-布-利-什”)
音节划分:Pub·lish
释义:发布。将软件模块上传至公共或私有仓库,使其可供他人下载和使用。
扩展信息:过去式 published;名词 publisher, publication。词根 publicus(公共的)。近义词:release, distribute。
注意事项:在 Go 模块生态中,“publish” 特指使模块可通过 Go 工具链获取(如发布到 GitHub)。
例句:You publish new versions of the module as you improve it.
中文翻译:当您改进模块时,可发布其新版本。 - Production
词性:名词
音标:/prəˈdʌkʃn/(“普-拉-达-克-申”)
音节划分:Pro·duc·tion
释义:生产环境。指软件正式对外提供服务的运行环境,区别于开发或测试环境。
扩展信息:形容词 productive;动词 produce。词根 producere(生产)。
注意事项:“production use” 是固定搭配,强调“真实业务场景下的使用”。
例句:Test the new version before putting it into production use.
中文翻译:在将其投入生产使用前测试新版本。 - Reproducible
词性:形容词
音标:/ˌriːprəˈduːsəbl/(“瑞-普-洛-杜-斯-厄-波”)
音节划分:Re·pro·du·ci·ble
释义:可重现的。指在相同输入和依赖条件下,构建过程能产生完全一致的输出结果。
扩展信息:动词 reproduce;名词 reproducibility。词根 re-(再次)+ producere(生产)。近义词:repeatable, consistent。
注意事项:Go 模块系统的核心目标之一就是确保构建的可重现性。
例句:This keeps builds reproducible.
中文翻译:这确保了构建的可重现性。 - Operator
词性:名词
音标:/ˈɑːpəreɪtər/(“阿-珀-雷-特”)
音节划分:Op·er·a·tor
释义:运算符。编程语言中用于执行特定操作的符号(如:=,+,==)。
扩展信息:动词 operate;形容词 operational。词根 operari(工作)。
注意事项:此处特指 Go 中的短变量声明运算符:=,非通用“操作员”含义。
例句:In Go, the := operator declares and initializes a variable.
中文翻译:在 Go 中,:=运算符用于声明并初始化变量。 - Format
词性:名词 / 动词
音标:/ˈfɔːrmæt/(“佛-热-麦-特”)
音节划分:For·mat
释义:格式。指数据或文本的组织结构或呈现样式;作动词时指按特定格式排版或转换。
扩展信息:形容词 formatted;动词过去式 formatted。词根 forma(形状)。
注意事项:在fmt.Sprintf中,“format string” 指含格式动词(如%v)的模板字符串。
例句:Sprintf substitutes values into the format string.
中文翻译:Sprintf 将值代入格式字符串中。 - Intend
词性:动词
音标:/ɪnˈtend/(“因-腾-德”)
音节划分:In·tend
释义:打算,意图。表示计划做某事或使某物用于特定目的;在技术语境中常用于描述模块、接口或函数的设计目的。
扩展信息:过去式 intended;过去分词 intended;名词 intention;形容词 intentional。词根 in-(向内)+ tendere(伸展、指向),本义“将心思朝向某事”。近义词:plan, mean, aim。
注意事项:在 Go 文档中高频出现于被动结构 “is intended to...”,强调设计意图而非偶然行为;不可与 “pretend”(假装)混淆。常见误用是将其后接不定式时遗漏 “to”(正确:intend to do)。
例句:The library is intended to be imported by other applications.
中文翻译:该库旨在被其他应用程序导入使用。 - Discrete
词性:形容词
音标:/dɪˈskriːt/(“迪-斯-克-瑞-特”)
音节划分:Dis·crete
释义:离散的,独立的。指由分离、不连续的个体或单元组成的;在计算机科学中常用于描述彼此独立、边界清晰的组件、值或系统模块。
扩展信息:副词 discretely;名词 discreteness。词源拉丁语 discretus(分开的),是动词 discernere(区分)的过去分词,由 dis-(分开)+ cernere(筛选)构成。近义词:separate, distinct, individual;反义词:continuous, connected。
注意事项:极易与拼写相近的 “discreet”(谨慎的,低调的)混淆——二者发音相同但含义迥异。“Discrete” 强调“分离性”,“discreet” 强调“不张扬”。在 IT 领域(如 “discrete components”, “discrete values”, “a discrete set of functions”)始终使用 “discrete”。
例句:In a module, you collect packages for a discrete and useful set of functions.
中文翻译:在模块中,您将包组织起来,以提供一组独立且有用的功能。 - Analysis
词性:名词
音标:/əˈnæləsɪs/(“厄-纳-乐-瑟-斯”)
音节划分:A·nal·y·sis
释义:分析。指对系统、数据、代码或问题进行系统性分解与研究,以理解其结构、行为或潜在问题;在 IT 领域常用于性能分析、静态代码分析、需求分析等场景。
扩展信息:复数形式为 analyses /əˈnæləsiːz/;动词为 analyse(英式)或 analyze(美式);形容词为 analytical;副词为 analytically。词源希腊语 analysis(“解开”),由 ana-(向上、回)+ lysis(松开)构成。近义词:examination, evaluation, inspection。
注意事项:不可数名词,但有规则复数 analyses(注意发音变化);在技术文档中常与领域词搭配,如 “financial analysis”, “code analysis”, “log analysis”。避免误拼为 “analisis”(漏掉第二个 “a”)。
例句:You might create a module with functions for doing financial analysis.
中文翻译:您可以创建一个包含金融分析函数的模块。 - Functionality
词性:名词
音标:/ˌfʌŋkʃəˈnæləti/(“范-克-夏-纳-乐-提”)
音节划分:Func·tion·al·i·ty
释义:功能,功能性。指软件、模块或系统所提供的具体能力或操作集合;在 IT 领域中常用于描述“某组件能做什么”。
扩展信息:不可数名词;形容词形式为 functional;副词为 functionally;动词为 function(运作)。词根 functio(拉丁语“执行、履行”)+ -ality(抽象名词后缀)。近义词:capability, feature, capability set;反义概念:non-functionality(无功能)、bug。
注意事项:不可与 “function” 混淆——“function” 指单个函数或作用,而 “functionality” 强调整体功能集合或能力维度;常用于 “add/improve/provide functionality” 等搭配;技术文档中多用于评估模块价值(如 “core functionality”, “new functionality”)。
例句:As you add or improve functionality in your module, you publish new versions.
中文翻译:当您向模块中添加或改进功能时,可发布新版本。 - Shortcut
词性:名词
音标:/ˈʃɔːrtkʌt/(“肖-特-卡-特”)
音节划分:Short·cut
释义:快捷方式,捷径。在编程语境中,指语言提供的简化语法结构,用于以更少代码实现常见操作(如变量声明、初始化等)。
扩展信息:可数名词,复数 shortcuts;动词形式较少用(to shortcut 意为“绕过”);由 short(短)+ cut(切)构成,字面意为“切短路径”。近义词:syntactic sugar(语法糖)、convenience syntax;反义概念:verbose form(冗长写法)。
注意事项:在 Go 文档中特指:=这类语言内置的简写机制,非操作系统中的快捷方式(desktop shortcut);强调“等效但更简洁”,而非功能差异。常见误用是将其理解为“性能优化”——实际上:=与显式var声明在运行时无区别。
例句:In Go, the := operator is a shortcut for declaring and initializing a variable in one line.
中文翻译:在 Go 中,:=运算符是声明并初始化变量的快捷方式,可将两步合并为一行。 - Determine
词性:动词
音标:/dɪˈtɜːrmɪn/(“迪-特-欧-敏”)
音节划分:De·ter·mine
释义:确定,判定。指通过分析、计算或规则明确得出某事物的性质、值、类型或行为;在编程中常用于描述编译器、运行时或语言机制如何推断变量类型、依赖版本或执行路径。
扩展信息:过去式 determined;过去分词 determined;名词 determination;形容词 determinate(可确定的)、deterministic(确定性的)。词源拉丁语 determinare(“限定边界”),由 de-(完全)+ terminus(界限)构成。近义词:decide, infer, deduce, establish;反义词:guess, assume。
注意事项:在 Go 语境中高频出现于“类型推断”场景(如 “Go uses the value on the right to determine the variable's type”);强调基于明确规则的逻辑结论,而非主观判断。常见误用是与 “terminate”(终止)混淆——二者拼写和发音均不同。
例句:Go uses the value on the right to determine the variable's type.
中文翻译:Go 会根据右侧的值来确定变量的类型。 - Substitutes
词性:动词(第三人称单数形式)
音标:/ˈsʌbstɪtjuːts/(“萨-布-斯-提-秋-茨”)
音节划分:Sub·sti·tutes
释义:替代,代入。在编程中特指将占位符(如格式字符串中的%v)替换为实际值的过程。
扩展信息:原形动词 substitute;过去式 substituted;过去分词 substituted;名词 substitute(替代品);形容词 substitutable。词源拉丁语 substituere,由 sub-(在下、代替)+ statuere(安置)构成。近义词:replace, swap, plug in;反义词:retain, keep。
注意事项:在 Go 的fmt.Sprintf等函数上下文中,“substitutes” 强调按格式规则自动填充值,而非手动替换;常与 “for” 搭配(substitutes X for Y)。注意不要与 “substitutes as”(充当)混淆——此处是“用 A 替代 B”。
例句:Sprintf substitutes the name parameter's value for the %v format verb.
中文翻译:Sprintf 将 name 参数的值代入 %v 格式动词处。 - Verb
词性:名词
音标:/vɜːrb/(“沃-布”)
音节划分:Verb
释义:动词。在自然语言中表示动作或状态的词类;在编程(特别是格式化函数如fmt.Sprintf)中,“format verb” 指用于指定数据如何被格式化的占位符符号,如%v、%s、%d等。
扩展信息:可数名词,复数 verbs;形容词 verbal;副词 verbally。词源拉丁语 verbum(“词、话语”)。在 Go 的fmt包文档中,“format verb” 是标准术语。近义表达:placeholder(占位符)、conversion specifier(转换说明符,源自 C 语言)。
注意事项:在 IT 技术语境下(尤其是 Go),“verb” 几乎专指格式动词(format verb),而非语言学中的动词;常见格式动词包括%v(默认格式)、%s(字符串)、%d(十进制整数)等。避免与 “word” 或 “operator” 混淆——“verb” 在此是格式语法的一部分。
例句:Sprintf substitutes the name parameter's value for the %v format verb.
中文翻译:Sprintf 将 name 参数的值代入 %v 格式动词处。 - Capital
词性:形容词 / 名词
音标:/ˈkæpɪtl/(“卡-皮-特-欧”)
音节划分:Cap·i·tal
释义:
- 作形容词时,意为“大写的”,指字母形式为大写(如 A, B, C),与小写(lowercase)相对;
- 作名词时,可指“首都”或“资本”,但在 Go 语言上下文中仅涉及“大写字母”含义。
在 IT 领域(尤其是 Go)中,“capital letter” 特指标识符首字母大写,是决定其是否为导出名(exported name)的关键规则。
扩展信息:
- 形容词用法无比较级;名词复数 capitals;
- 副词形式不直接派生,但可通过 “in capital letters” 表达“用大写字母书写”;
- 词源拉丁语 capitalis(“首要的”),源自 caput(头),引申为“首字母”;
- 近义表达:uppercase(更通用的计算机术语);反义:lowercase, small letter。
注意事项:
-
在 Go 文档中,“starts with a capital letter” 是固定表述,用于判断标识符是否可被其他包访问;
-
不可与 “capital” 的经济/地理含义混淆——技术语境下仅关注字母大小写;
-
虽然 “uppercase” 更常用于泛指大写,但 Go 官方文档偏好使用 “capital letter” 描述导出规则。
例句:In Go, a function whose name starts with a capital letter can be called by other packages.
中文翻译:在 Go 中,函数名以大写字母开头时,可被其他包调用。
三、短语表梳理(共新增 5 个短语)
- Intended to be imported
释义:旨在被导入。描述模块或包的设计目的——供其他代码通过 import 机制复用。
注意事项:被动语态结构,强调“设计意图”;“imported” 特指 Go 的包导入,非通用“引入”。
例句:The library is intended to be imported by other applications.
中文翻译:该库旨在被其他应用程序导入使用。 - A discrete and useful set of functions
释义:一组独立且有用的功能。定义高质量 Go 模块应具备的特性:功能内聚、边界清晰、实用性强。
注意事项:“discrete”(离散的、独立的)是关键词,区别于 “discreet”(谨慎的);体现模块化设计原则。
例句:Collect packages for a discrete and useful set of functions.
中文翻译:将包组织起来,以提供一组独立且有用的功能。 - Put it into production use
释义:将其投入生产使用。指将经过验证的软件版本部署到真实业务环境中。
注意事项:固定工程术语;“production use” 强调“实际业务场景”,非测试或开发。
例句:Test the update before putting it into production use.
中文翻译:在将其投入生产使用前先进行测试。 - Exported name
释义:导出名。Go 语言特有概念,指首字母大写的标识符(函数、变量等),可被其他包访问。
注意事项:官方术语,不可拆解;常与 “unexported”(未导出)对比;决定包的公共 API。
例句:A function starting with a capital letter is an exported name.
中文翻译:以大写字母开头的函数是一个导出名。 - Taking the long way
释义:采用更冗长的方式。用于对比简洁写法(如:=)与显式写法(如var声明)。
注意事项:口语化比喻,非正式术语;仅用于教学对比,强调语言特性带来的简洁性。
例句:Taking the long way, you’d write: var message string.
中文翻译:若采用更冗长的方式,您会写成:var message string。
收获统计
- 本次新增单词总数:12 个
- 本次新增短语总数:5 个