按版本划分的 Go 特性

这是 Go 各个版本中出现的主要特性总结:

  • 1.25(2025 年 8 月)

    • 测试用的假时钟(Fake clock for testing)
    • 实验性 JSON v2(Experimental JSON v2)
    • 容器感知的 GOMAXPROCS(Container-aware GOMAXPROCS)
    • 实验性绿茶垃圾回收器(Experimental Green Tea garbage collector)
    • CSRF 保护(CSRF protection)
    • Wait group 的 Go 方法(Wait group Go method)
    • 飞行记录(Flight recording)
    • 更多 Root 方法(More Root methods)
    • 反射类型断言(Reflective type assertion)
    • 测试属性和输出(Test attributes and output)
    • 分组日志属性(Grouped attributes for logging)
    • 哈希克隆(Hash cloning)
  • 1.24(2025 年 2 月)

    • 泛型类型别名(Generic type aliases)
    • 弱指针(Weak pointers)
    • 更好的运行时终结器(Better runtime finalizers)
    • 内置map使用瑞士表重新实现(The builtin map is reimplemented using Swiss Tables)
    • 并发哈希树映射(Concurrent hash-trie map)
    • 目录范围的文件系统访问(Directory-scoped filesystem access)
    • 更快且更少出错的基准测试循环(Faster and less error-prone benchmark loops)
    • 测试上下文(Test context)
    • 丢弃日志处理程序(Discarding log handler)
    • 用于将对象的文本或二进制表示附加到字节切片的接口(Interfaces to append the textual or binary representation of an object to a byte slice)
    • 更多字节和字符串迭代器(More byte and string iterators)
    • 新的crypto包:sha3hkdfpbkdf2
    • 协议作为配置服务器或客户端使用的 HTTP 协议的简单方式(Protocols as a simple way to configure what HTTP protocols a server or client use)
    • 省略 JSON 编组中零值的选项(Option to omit zero values in JSON marshaling)
    • 生成密码安全的随机文本字符串(Generate cryptographically secure random text strings)
    • go.mod中的可执行工具依赖项(Executable tool dependencies in go.mod
    • JSON 输出用于构建、安装和测试命令(JSON output for build, install and test commands)
    • 基于 VCS 标签或提交的主模块版本(Main module's version based on the VCS tag or commit)
  • 1.23(2024 年 8 月)

    • for循环可以遍历迭代器函数(For loops can range over iterator functions)
    • 迭代器类型和拉式迭代器(Iterator types and pull iterators)
    • 切片迭代器(Slice iterators)
    • 映射迭代器(Map iterators)
    • 计时器和定时器停止后立即可进行垃圾回收(Timers and Tickers that are no longer referred to by the program become eligible for garbage collection immediately)
    • 避免定时器和定时器停止/重置后的陈旧接收(Avoid stale receives after Timers and Tickers Stop/Reset return)
    • 规范值(Canonical values)
    • 解析 cookie(Parse cookies)
    • 复制目录(Copy directories)
    • 重复切片(Repeat slices)
    • 原子位运算和或(Atomic bitwise and/or)
    • 遥测(Telemetry)
  • 1.22(2024 年 2 月)

    • 循环的每次迭代创建新变量以避免意外共享错误(Each iteration of the loop creates new variables to avoid accidental sharing bugs)
    • for循环可以遍历整数(For loops can range over integers)
    • 新的处理随机数的包(New package to work with random numbers)
    • HTTP 路由模式支持方法和通配符(HTTP routing patterns support methods and wildcards)
    • 连接切片(Concatenate slices)
    • 验证和比较 Go 版本字符串(Validate and compare Go version strings)
  • 1.21(2023 年 8 月)

    • 新的minmax内置函数计算参数中的最小/最大价值(New min and max built-ins calculate the smallest/largest value among arguments)
    • 新的clear内置函数删除映射中的所有元素或零化切片中的所有元素(New clear built-in deletes all elements from a map or zeroes all elements of a slice)
    • 带有级别结构的日志记录(Structured logging with levels)
    • 切片的常见操作(Common operations on slices)
    • 映射的常见操作(Common operations on maps)
    • 比较有序值(Compare ordered values)
    • 配置文件引导优化(Profile-guided optimization (PGO) performs optimizations based on run-time profile information)
    • WebAssembly 系统接口端口(WebAssembly System Interface port)
  • 1.20(2023 年 2 月)

    • 允许从切片转换为数组(Allow conversion from a slice to an array)
    • 按定义顺序逐个字段比较结构值(Compare struct values one field at a time, in order of definition)
    • 可比较类型现在可以满足comparable约束,即使类型参数不是严格可比较的(Comparable types may now satisfy comparable constraints, even if the type arguments are not strictly comparable)
    • 允许包装多个错误(Allow wrapping multiple errors)
    • 用给定错误取消上下文(Cancel a context with a given error ("cause"))
    • 国际化友好的时间格式字符串(International-friendly time format strings)
    • 椭圆曲线 Diffie-Hellman 协议(Elliptic Curve Diffie-Hellman protocol)
    • go命令默认在没有 C 工具链的系统上禁用cgo
  • 1.19(2022 年 8 月)

    • 修订的内存模型(Revised memory model)
    • 对 Go 使用的总内存的软内存限制(Soft memory limit on the total amount of memory Go uses)
    • 限制总 GC CPU 利用率为 50%(Limit total GC CPU utilization to 50%, excluding idle time)
    • 原子值和指针类型(Atomic value and pointer types)
    • 支持文档注释中的链接、列表和更清晰的标题(Support for links, lists, and clearer headings in doc comments)
  • 1.18(2022 年 3 月)

    • 使用类型参数的泛型编程(Generic programming using type parameters)
    • 模块版本、版本控制信息和可执行文件中的构建标志(Module versions, version control information, and build flags embedded in executable files)
    • 更好的 IP 地址类型和辅助函数(A better IP address type and helper functions)
    • go get不再构建或安装包(go get no longer builds or installs packages)
    • 模糊测试(Fuzzing)
  • 1.17(2021 年 8 月)

    • 允许从切片转换为数组指针(Allow conversion from a slice to an array pointer)
    • 集中式管理(c)go 指针句柄的设施(Centralized facility for managing (c)go pointer handles)
    • 使用go:build指令的抗错误构建约束(Bug-resistant build constraints using the go:build directive)
  • 1.16(2021 年 2 月)

    • 使用go:embed指令将文件嵌入可执行文件(Embed files into the executable using the go:embed directive)
    • 从 Go 运行时读取实现定义的指标(Read implementation-defined metrics from the Go runtime)
    • 文件系统接口(File system interfaces)
    • 废弃io/ioutil包(The io/ioutil package is deprecated)
    • 默认启用模块感知模式(Module-aware mode is enabled by default (GO111MODULE=on))
    • 构建命令默认不再修改go.modgo.sum(Build commands like go build no longer modify go.mod and go.sum by default)
  • 1.15(2020 年 8 月)

    • 将时区数据库嵌入程序(Embed the timezone database into a program)
  • 1.14(2020 年 2 月)

    • 允许嵌入重叠接口(Allow embedding overlapping interfaces)
    • Goroutines 现在是异步可抢占的(Goroutines are now asynchronously preemptible)
    • 字节序列上的哈希函数(Hash functions on byte sequences, to implement hash tables and other maps)
  • 1.13(2019 年 9 月)

    • 统一和现代化的数字字面量前缀(Uniform and modernized set of number literal prefixes)
    • 允许有符号整数值作为移位计数(Permit signed integer values as shift count)
    • 错误包装(Error wrapping)
    • Ed25519 签名方案(Ed25519 signature scheme)
  • 1.12(2019 年 2 月)

    • 映射以键排序顺序打印(Maps are printed in key-sorted order)
  • 1.11(2018 年 8 月)

    • 模块作为管理依赖项的方式(Modules as a way to manages dependencies)
    • WebAssembly 端口(WebAssembly port)
  • 1.10(2018 年 2 月)

    • go build维护最近构建的包的缓存
    • go test缓存测试结果并自动运行go vet
  • 1.9(2017 年 8 月)

    • 类型别名(Type aliases)
    • time包中的单调时钟(Monotonic clock in the time package)
    • 位计数和操作(Bit counting and manipulation)
    • 并发安全的映射(Concurrent-safe map)
    • 测试和基准测试辅助函数(Test and benchmark helper functions)
    • 并行编译
  • 1.8(2017 年 2 月)

    • 转换值时忽略标签(Ignore tags when converting a value from one struct type to another)
    • 垃圾回收器不再认为函数的所有参数都是活动的(The garbage collector no longer considers arguments live throughout the entirety of a function)
    • sort包中的切片相关函数(Slice-related functions in the sort package)
    • HTTP/2 服务器推送(HTTP/2 server pushes)
    • HTTP 服务器优雅关闭(HTTP server graceful shutdown)
    • database/sql包中的上下文支持(Context support in the database/sql package)
  • 1.7(2016 年 8 月)

    • 上下文的截止日期和取消(Deadlines and cancellation with contexts)
    • HTTP 请求中的跟踪事件(Tracing events within HTTP requests)
    • 子测试和子基准测试(Sub-tests and sub-benchmarks)
  • 1.6(2016 年 2 月)

    • HTTP/2 支持
    • 供应商
  • 1.5(2015 年 8 月)

    • 编译器和运行时完全用 Go 编写
    • 并发垃圾回收器
    • 默认将GOMAXPROCS设置为可用核心数
    • 内部包
    • go tool trace命令用于程序执行的细粒度跟踪
    • go doc命令用于构建包文档
  • 1.4(2014 年 12 月)

    • 不带变量的for-range循环
    • 禁止在**T上调用方法
    • go generate命令用于在编译前生成源代码
  • 1.3(2014 年 6 月)

    • 连续的 goroutine 堆栈
  • 1.2(2013 年 12 月)

    • 任何显式或隐式需要评估nil地址的表达式都是错误的
    • 完整的切片表达式用于指定切片的容量和长度
    • 新的encoding包提供标准编码接口
    • 新的image/color/palette包提供标准颜色调色板
    • fmt格式化规范中的索引操作
  • 1.1(2013 年 5 月)

    • 整数除法除以零是编译时错误
    • 方法值
    • 竞争检测器
    • 新的go/format包用于访问go fmt命令的格式化功能
    • 新的net/http/cookiejar包用于管理 HTTP 饼干
  • 1.0(2012 年 3 月)

    • 第一个稳定版本
阅读 7
0 条评论