这是用户在 2025-8-2 19:21 为 https://go.dev/doc/ 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?

Documentation  文档

The Go programming language is an open source project to make programmers more productive.
Go 编程语言是一个开源项目,旨在提高程序员的工作效率。

Go is expressive, concise, clean, and efficient. Its concurrency mechanisms make it easy to write programs that get the most out of multicore and networked machines, while its novel type system enables flexible and modular program construction. Go compiles quickly to machine code yet has the convenience of garbage collection and the power of run-time reflection. It's a fast, statically typed, compiled language that feels like a dynamically typed, interpreted language.
Go 语言富有表现力、简洁且高效。其并发机制使得编写能充分利用多核和网络设备的程序变得轻而易举,而新型的类型系统则支持灵活且模块化的程序构建。Go 可快速编译为机器码,同时兼具垃圾回收的便利性与运行时反射的强大功能。作为一门快速的静态类型编译型语言,它却给人以动态类型解释型语言的开发体验。

Getting Started  入门指南

Installing Go  安装 Go ¶

Instructions for downloading and installing Go.
下载和安装 Go 的说明。

Tutorial: Getting started
教程:入门 ¶

A brief Hello, World tutorial to get started. Learn a bit about Go code, tools, packages, and modules.
简明 Hello, World 教程入门指南。了解 Go 语言代码、工具、包和模块的基础知识。

Tutorial: Create a module
教程:创建模块 ¶

A tutorial of short topics introducing functions, error handling, arrays, maps, unit testing, and compiling.
简明教程:函数、错误处理、数组、映射、单元测试与编译介绍。

Tutorial: Getting started with multi-module workspaces
教程:多模块工作区入门 ¶

Introduces the basics of creating and using multi-module workspaces in Go. Multi-module workspaces are useful for making changes across multiple modules.
介绍如何在 Go 中创建和使用多模块工作区的基础知识。多模块工作区有助于跨多个模块进行修改。

Tutorial: Developing a RESTful API with Go and Gin
Tutorial: Developing a RESTful API with Go and Gin ¶ 教程:使用 Go 和 Gin 开发 RESTful API ¶

Introduces the basics of writing a RESTful web service API with Go and the Gin Web Framework.
介绍使用 Go 语言和 Gin Web 框架编写 RESTful Web 服务 API 的基础知识。

Tutorial: Getting started with generics
教程:泛型入门指南 ¶

With generics, you can declare and use functions or types that are written to work with any of a set of types provided by calling code.
使用泛型,你可以声明并使用那些设计用于处理调用代码提供的任何类型集的函数或类型。

Tutorial: Getting started with fuzzing
教程:模糊测试入门 ¶

Fuzzing can generate inputs to your tests that can catch edge cases and security issues that you may have missed.
模糊测试可以为你的测试生成输入,从而捕捉到你可能遗漏的边缘情况和安全问题。

Writing Web Applications
编写 Web 应用程序 ¶

Building a simple web application.
构建一个简单的 Web 应用程序。

How to write Go code
如何编写 Go 代码¶

This doc explains how to develop a simple set of Go packages inside a module, and it shows how to use the go command to build and test packages.
本文档阐述了如何在模块内开发一组简单的 Go 包,并演示了如何使用 go 命令构建和测试这些包。

A Tour of Go
Go 语言之旅

An interactive introduction to Go in four sections. The first section covers basic syntax and data structures; the second discusses methods and interfaces; the third is about Generics; and the fourth introduces Go's concurrency primitives. Each section concludes with a few exercises so you can practice what you've learned. You can take the tour online or install it locally with:
Go 语言交互式导览共分四部分。第一部分涵盖基础语法与数据结构;第二部分探讨方法与接口;第三部分讲解泛型;第四部分介绍 Go 的并发原语。每章节末尾均设有练习题供实践所学内容。您可在线学习导览课程,亦可通过以下命令本地安装:

	$ go install golang.org/x/website/tour@latest
	

This will place the tour binary in your GOPATH's bin directory.
这将会把 tour 二进制文件放置到您 GOPATH 的 bin 目录中。

Using and understanding Go
使用和理解 Go 语言

Effective Go  《高效 Go 编程》¶

A document that gives tips for writing clear, idiomatic Go code. A must read for any new Go programmer. It augments the tour and the language specification, both of which should be read first.
一份关于编写清晰地道 Go 代码技巧的文档。每位 Go 语言新手的必读材料。本文档对官方教程和语言规范进行了补充说明,建议开发者优先阅读前述两项资料。

Frequently Asked Questions (FAQ)
常见问题解答 (FAQ) ¶

Answers to common questions about Go.
Go 常见问题解答

Editor plugins and IDEs
编辑器插件与集成开发环境¶

A document that summarizes commonly used editor plugins and IDEs with Go support.
常用 Go 语言编辑器插件与 IDE 支持文档

Diagnostics  诊断 ¶

Summarizes tools and methodologies to diagnose problems in Go programs.
总结用于诊断 Go 程序中问题的工具和方法论。

A Guide to the Go Garbage Collector
Go 垃圾回收器指南 ¶

A document that describes how Go manages memory, and how to make the most of it.
一份描述 Go 如何管理内存以及如何充分利用内存的文档。

Managing dependencies  依赖管理 ¶

When your code uses external packages, those packages (distributed as modules) become dependencies.
当你的代码使用外部软件包时,这些(以模块形式分发的)软件包便成为依赖项。

Fuzzing  模糊测试 ¶

Main documentation page for Go fuzzing.
Go 模糊测试主文档页面

Coverage for Go applications
Go 应用程序的覆盖率

Main documentation page for coverage testing of Go applications.
Go 应用覆盖率测试主文档页面。

Profile-guided optimization
配置文件引导的优化 ¶

Main documentation page for profile-guided optimization (PGO) of Go applications.
Go 应用程序配置文件引导优化(PGO)的主要文档页面。

References  参考文献

Package Documentation  包文档 ¶

The documentation for the Go standard library.
Go 标准库的文档。

Command Documentation  命令文档 ¶

The documentation for the Go tools.
Go 工具文档。

Language Specification
语言规范 ¶

The official Go Language specification.
Go 语言官方规范

Go Modules Reference
Go 模块参考

A detailed reference manual for Go's dependency management system.
Go 依赖管理系统详细参考手册。

go.mod file reference  go.mod 文件参考

Reference for the directives included in a go.mod file.
go.mod 文件中包含的指令参考。

The Go Memory Model
Go 内存模型

A document that specifies the conditions under which reads of a variable in one goroutine can be guaranteed to observe values produced by writes to the same variable in a different goroutine.
规定在何种条件下,一个协程中对变量的读取操作可保证观察到另一个协程中对同一变量写入操作所产生值的文档。

Contribution Guide  贡献指南 ¶

Contributing to Go.  为 Go 语言做贡献。

Release History  发布历史 ¶

A summary of the changes between Go releases.
Go 语言各版本更新内容摘要

Accessing databases  访问数据库

Tutorial: Accessing a relational database
教程:访问关系型数据库 ¶

Introduces the basics of accessing a relational database using Go and the database/sql package in the standard library.
介绍了使用 Go 语言和标准库中的 database/sql 包访问关系型数据库的基础知识。

Accessing relational databases
访问关系型数据库¶

An overview of Go's data access features.
Go 语言数据访问功能概述

Opening a database handle
打开数据库句柄¶

You use the Go database handle to execute database operations. Once you open a handle with database connection properties, the handle represents a connection pool it manages on your behalf.
您使用 Go 数据库句柄执行数据库操作。一旦通过数据库连接属性打开句柄,该句柄即表示其代您管理的连接池。

Executing SQL statements that don't return data
正在执行不返回数据的 SQL 语句 ¶

For SQL operations that might change the database, including SQL INSERT, UPDATE, and DELETE, you use Exec methods.
对于可能改变数据库的 SQL 操作,包括 SQL INSERTUPDATEDELETE ,您使用 Exec 方法。

Querying for data
查询数据 ¶

For SELECT statements that return data from a query, using the Query or QueryRow method.
对于从查询返回数据的 SELECT 语句,使用 QueryQueryRow 方法。

Using prepared statements
使用预处理语句 ¶

Defining a prepared statement for repeated use can help your code run a bit faster by avoiding the overhead of re-creating the statement each time your code performs the database operation.
为重复使用定义预编译语句,可避免每次执行数据库操作时重新创建语句的开销,从而让代码运行稍快一些。

Executing transactions
执行事务 ¶

sql.Tx exports methods representing transaction-specific semantics, including Commit and Rollback, as well as methods you use to perform common database operations.
sql.Tx 导出代表事务特定语义的方法,包括 CommitRollback ,以及用于执行常见数据库操作的方法。

Canceling in-progress database operations
取消进行中的数据库操作 ¶

Using context.Context, you can have your application's function calls and services stop working early and return an error when their processing is no longer needed.
使用 context.Context,可以让应用程序的函数调用和服务在不再需要处理时提前终止并返回错误。

Managing connections  管理连接 ¶

For some advanced programs, you might need to tune connection pool parameters or work with connections explicitly.
对于某些高级程序,您可能需调整连接池参数或显式处理连接。

Avoiding SQL injection risk
避免 SQL 注入风险¶

You can avoid an SQL injection risk by providing SQL parameter values as sql package function arguments
可通过提供 SQL 参数值作为 sql 包函数参数来避免 SQL 注入风险

Developing modules  开发模块

Developing and publishing modules
开发和发布模块 ¶

You can collect related packages into modules, then publish the modules for other developers to use. This topic gives an overview of developing and publishing modules.
您可以将相关包收集到模块中,然后发布这些模块供其他开发者使用。本主题概述了如何开发和发布模块。

Module release and versioning workflow
模块发布和版本控制流程 ¶

When you develop modules for use by other developers, you can follow a workflow that helps ensure a reliable, consistent experience for developers using the module. This topic describes the high-level steps in that workflow.
在开发供其他开发者使用的模块时,可遵循一套工作流程,以确保开发者使用模块时获得可靠一致的体验。本主题将阐述该工作流程中的高级别步骤。

Managing module source
管理模块源 ¶

When you're developing modules to publish for others to use, you can help ensure that your modules are easier for other developers to use by following the repository conventions described in this topic.
在开发要发布供他人使用的模块时,遵循本主题所述的存储库约定可帮助确保其他开发人员更易于使用您的模块。

Organizing a Go module
组织 Go 模块¶

What is the right way to organize the files and directories in a typical Go project? This topic discusses some common layouts depending on the kind of module you have.
如何正确组织典型 Go 项目中的文件和目录?本主题根据模块类型讨论了几种常见布局。

Developing a major version update
开发主版本更新 ¶

A major version update can be very disruptive to your module's users because it includes breaking changes and represents a new module. Learn more in this topic.
主要版本更新可能会给您的模块用户带来重大影响,因其包含重大变更且相当于全新模块。请参阅此主题了解更多信息。

Publishing a module
发布模块¶

When you want to make a module available for other developers, you publish it so that it's visible to Go tools. Once you've published the module, developers importing its packages will be able to resolve a dependency on the module by running commands such as go get.
当您希望某个模块可供其他开发者使用时,需将其发布以使 Go 工具可见。模块发布后,开发者导入其包时,可通过运行诸如 go get 等命令解析对该模块的依赖。

Module version numbering
模块版本编号 ¶

A module's developer uses each part of a module's version number to signal the version’s stability and backward compatibility. For each new release, a module's release version number specifically reflects the nature of the module's changes since the preceding release.
模块开发者通过版本号的各个部分来标识版本的稳定性和向后兼容性。每次新发布时,模块的发布版本号会具体体现自先前版本以来的变更性质。

Talks  对话

A Video Tour of Go
Go 语言视频导览¶

Three things that make Go fast, fun, and productive: interfaces, reflection, and concurrency. Builds a toy web crawler to demonstrate these.
Go 语言实现快速、有趣且高效的三大要素:接口、反射与并发。通过构建一个演示用的网络爬虫来展现这些特性。

Code that grows with grace
优雅成长的代码 ¶

One of Go's key design goals is code adaptability; that it should be easy to take a simple design and build upon it in a clean and natural way. In this talk Andrew Gerrand describes a simple "chat roulette" server that matches pairs of incoming TCP connections, and then use Go's concurrency mechanisms, interfaces, and standard library to extend it with a web interface and other features. While the function of the program changes dramatically, Go's flexibility preserves the original design as it grows.
Go 语言的核心设计目标之一是代码适应性;即能够轻松地在简洁设计的基础上,以清晰自然的方式进行功能拓展。本次演讲中,安德鲁·格兰德将演示一个简易的"聊天轮盘"服务器:该服务器通过匹配传入的 TCP 连接对,并运用 Go 语言的并发机制、接口特性及标准库,为其扩展出网络接口等附加功能。尽管程序功能发生显著变化,Go 语言的灵活性仍能在发展过程中保持最初的架构设计。

Go Concurrency Patterns
Go 并发模式¶

Concurrency is the key to designing high performance network services. Go's concurrency primitives (goroutines and channels) provide a simple and efficient means of expressing concurrent execution. In this talk we see how tricky concurrency problems can be solved gracefully with simple Go code.
并发是设计高性能网络服务的关键。Go 的并发原语(goroutine 和 channel)提供了一种简洁高效的并发执行表达方式。本次演讲将展示如何用简单的 Go 代码优雅解决棘手的并发问题。

Advanced Go Concurrency Patterns
高级 Go 并发模式¶

This talk expands on the Go Concurrency Patterns talk to dive deeper into Go's concurrency primitives.
本次演讲在 Go 并发模式演讲的基础上,深入探讨 Go 语言的并发原语。

More  更多 ¶

See the Go Talks site and wiki page for more Go talks.
请访问 Go Talks 网站和维基页面以获取更多 Go 技术演讲。

Codewalks

Guided tours of Go programs.
Go 程序引导式教程。

Language  语言

Packages  

Modules  模块

  • Using Go Modules - an introduction to using modules in a simple project.
    使用 Go Modules - 在简单项目中使用模块简介
  • Migrating to Go Modules - converting an existing project to use modules.
    迁移到 Go Modules - 将现有项目转换为使用模块。
  • Publishing Go Modules - how to make new versions of modules available to others.
    发布 Go 模块——如何向他人提供模块新版本。
  • Go Modules: v2 and Beyond - creating and publishing major versions 2 and higher.
    Go Modules:v2 及以上版本 - 创建并发布主版本 2 及更高版本。
  • Keeping Your Modules Compatible - how to keep your modules compatible with prior minor/patch versions.
    保持模块兼容性 - 如何确保模块与先前次要/修补版本兼容

Tools  工具

  • About the Go command - why we wrote it, what it is, what it's not, and how to use it.
    关于 Go 命令——编写原因、功能定位、非适用场景及用法说明。
  • Go Doc Comments - writing good program documentation
    Go 文档注释——编写优质程序文档
  • Debugging Go Code with GDB
    使用 GDB 调试 Go 代码
  • Data Race Detector - a manual for the data race detector.
    数据竞争检测器 - 数据竞争检测器的使用手册。
  • A Quick Guide to Go's Assembler - an introduction to the assembler used by Go.
    Go 汇编快速指南——Go 语言所用汇编器简介。
  • C? Go? Cgo! - linking against C code with cgo.
    C? Go? Cgo! - 使用 cgo 链接 C 代码。
  • Profiling Go Programs - tools for measuring your code's CPU and memory usage
    剖析 Go 程序——测量代码 CPU 和内存使用情况的工具
  • Introducing the Go Race Detector - an introduction to the race detector.
    Introducing the Go Race Detector - an introduction to the race detector. 引入 Go Race Detector——竞争检测器入门介绍。
  • Gopls: The language server for Go - getting the most out your editor when working in Go.
    gopls:专为 Go 设计的语言服务器——助您在 Go 开发中充分利用编辑器功能。

Wiki

The Go Wiki, maintained by the Go community, includes articles about the Go language, tools, and other resources.

See the Learn page at the Wiki for more Go learning resources.
参见 Wiki 上的“学习页面”获取更多 Go 学习资源。

Non-English Documentation
非英语文档

See the NonEnglish page at the Wiki for localized documentation.
参见维基上的非英语页面以获取本地化文档。