Go 1.27

Go 1.27

The Go Blog: Go 1.27 is released Go 博客:Go 1.27 正式发布

Nicholas Husin, on behalf of the Go team 19 August 2026 Nicholas Husin,代表 Go 团队 2026 年 8 月 19 日

Today the Go team is pleased to release Go 1.27. You can find its binary archives and installers on the download page. Go 1.27 brings major enhancements across the language, toolchain, runtime, and standard library. Below are some of the key highlights. 今天,Go 团队很高兴地发布了 Go 1.27。您可以在下载页面找到其二进制归档文件和安装程序。Go 1.27 在语言、工具链、运行时和标准库方面带来了重大改进。以下是一些主要亮点。

Language changes

语言变更

Go 1.27 introduces three notable updates to the language specification. First, generic methods are now supported. For example, see math/rand/v2.Rand: Go 1.27 对语言规范引入了三项值得注意的更新。首先,现在支持泛型方法。例如,请参阅 math/rand/v2.Rand

// Prior to Go 1.27, a separate method on Rand had to be added for each type
// (unsigned integer methods omitted for brevity).
func (r *Rand) Int32N(n int32) int32
func (r *Rand) Int64N(n int64) int64
func (r *Rand) IntN(n int) int

// Go 1.27 adds a new generic method that works for all integer types.
func (r *Rand) N[Int intType](n Int) Int

Second, a key in a struct literal may now be any valid field selector for the struct type, allowing fields in nested or embedded structs to be initialized directly: 其次,结构体字面量中的键现在可以是该结构体类型的任何有效字段选择器,从而允许直接初始化嵌套或嵌入式结构体中的字段:

type Habitat struct { Burrow string }
type Gopher struct {
    Name string
    Habitat // Embedded struct.
}

// Go 1.27 allows using Burrow as a key directly.
g := Gopher{
    Name: "Gopher",
    Burrow: "Burrow #42",
}

Finally, function type inference has been generalized to apply in all assignment contexts. Generic functions can now be used without explicit type arguments in composite literals, type conversions, and channel sends: 最后,函数类型推断已泛化,适用于所有赋值上下文。现在,在复合字面量、类型转换和通道发送中,无需显式类型参数即可使用泛型函数:

func GenericFormatter[T any](v T) string { return fmt.Sprintf("value: %v", v) }
type IntFormatter func(int) string

// Go 1.27 infers T = int in composite literals, conversions, and channel sends.
formatters := []IntFormatter{GenericFormatter}
fn := IntFormatter(GenericFormatter)
ch := make(chan IntFormatter, 1)
ch <- GenericFormatter

Tool improvements

工具改进

go fix includes several new modernizers: atomictypes, embedlit, slicesbackward, and unsafefuncs. go fix 包含几个新的现代化工具:atomictypesembedlitslicesbackwardunsafefuncs

go doc now supports package@version queries such as go doc example.com/pkg@v1.2.3. go doc 现在支持 package@version 查询,例如 go doc example.com/pkg@v1.2.3

go mod tidy now automatically consolidates multiple require blocks in go.mod into a standard direct and indirect two-block structure. go mod tidy 现在会自动将 go.mod 中的多个 require 块合并为标准的直接依赖和间接依赖两个块结构。

Performance and runtime

性能与运行时

Size-specialized memory allocation reduces small object (<80B) allocation costs by up to 30%, improving overall performance by ~1% for allocation-heavy programs. 大小专用内存分配将小对象(<80B)的分配成本降低了高达 30%,使内存分配密集型程序的整体性能提升了约 1%。

The goroutineleak profile in runtime/pprof is now generally available, allowing automatic detection of permanently blocked goroutines. runtime/pprof 中的 goroutineleak 分析现已正式可用,允许自动检测永久阻塞的 goroutine。

Standard library additions

标准库新增内容

encoding/json/v2 provides high-level JSON processing with configurable options and stricter defaults, alongside encoding/json/jsontext for low-level streaming. The existing encoding/json package is now backed by the v2 implementation for faster unmarshaling while maintaining backwards compatibility. encoding/json/v2 提供了具有可配置选项和更严格默认值的高级 JSON 处理功能,同时还提供了用于底层流式处理的 encoding/json/jsontext。现有的 encoding/json 包现在由 v2 实现提供支持,在保持向后兼容性的同时实现了更快的反序列化。

crypto/mldsa implements the post-quantum ML-DSA signature scheme (FIPS 204), integrated into crypto/x509 and crypto/tls. crypto/mldsa 实现了后量子 ML-DSA 签名方案(FIPS 204),并集成到了 crypto/x509crypto/tls 中。

uuid provides native support for generating and parsing UUIDs. uuid 提供了生成和解析 UUID 的原生支持。

simd and architecture-specific simd/archsimd provide experimental SIMD support. simd 和特定于架构的 simd/archsimd 提供了实验性的 SIMD 支持。

net/http/httptest adds NewTestServer, providing an in-memory fake network suitable for use with the testing/synctest package. net/http/httptest 新增了 NewTestServer,提供了一个适用于 testing/synctest 包的内存中模拟网络。

Please read the Go 1.27 release notes for the complete list of changes and details. Over the next few weeks, follow-up blog posts will cover some of the topics relevant to Go 1.27 in more detail. Check back later to read those posts. 请阅读 Go 1.27 发行说明以获取完整的变更列表和详细信息。在接下来的几周内,后续的博客文章将更详细地介绍与 Go 1.27 相关的一些主题。请稍后回来阅读这些文章。

Thanks to everyone who contributed to this release by writing code, filing bugs, trying out experimental additions, and testing release candidates. As always, if you notice any problems, please file an issue. We hope you enjoy using Go 1.27! 感谢所有为本次发布做出贡献的人,包括编写代码、提交错误报告、尝试实验性功能以及测试发布候选版本。一如既往,如果您发现任何问题,请提交 Issue。希望您喜欢使用 Go 1.27!