序言
为什么要了解版本信息?
- 版本更新会引入新的语言特性和改进,可以让开发者更加高效地编写代码和解决问题。
- 版本更新可能会更改标准库、包和API的行为,需要开发者进行适应和更新。
- 了解版本更新可以帮助开发者更好地利用Go语言的性能和功能,提高代码的质量和效率。
- 版本更新通常会修复漏洞和错误,提高代码的安全性和可靠性。
- Go语言社区和生态系统的发展也与版本更新密切相关,了解版本更新可以帮助开发者更好地了解Go语言的生态环境和未来发展方向
如何全面的了解版本信息?
通过Go官网的The Go Blog可以检索出每个版本的发布信息,以及详细的版本说明。本文参考以下文章:
- Go 1.12 Release Notes
- Go 1.13 Release Notes
- Go 1.14 Release Notes
- Go 1.15 Release Notes
为了防止内容因为作者在翻译时理解错误,因此大部分会从官网原文摘取出来,其中也只会摘取一些重点的更新。
一、 Go1.12
发布时间
25 February 2019
版本概要
- opt-in support for TLS 1.3
- improved modules support
- support for windows/arm
- improved macOS & iOS forwards compatibility
- the race detector is now supported on linux/arm64.
- cgo is now supported on linux/ppc64.
版本重点内容
1. improved modules support
2. godoc and go doc
Users should use go doc for command-line help output instead. Go 1.12 is the last release that will include the godoc webserver; go doc now supports the -all flag, which will cause it to print all exported APIs and their documentation, as the godoc command line used to do. go doc also now includes the -src flag, which will show the target's source code.
3. trace supports plotting mutator utilization curves
The trace tool now supports plotting mutator utilization curves, including cross-references to the execution trace. These are useful for analyzing the impact of the garbage collector on application latency and throughput.
4. Runtime
- Go 1.12 significantly improves the performance of sweeping when a large fraction of the heap remains live. This reduces allocation latency immediately following a garbage collection.
- The Go runtime now releases memory back to the operating system more aggressively, particularly in response to large allocations that can't reuse existing heap space.
- The Go runtime's timer and deadline code is faster and scales better with higher numbers of CPUs. In particular, this improves the performance of manipulating network connection deadlines.
- Go 1.12 improves the accuracy of memory profiles by fixing overcounting of large heap allocations.
5. adds opt-in support for TLS 1.3
Go 1.12 adds opt-in support for TLS 1.3 in the crypto/tls package as specified by RFC 8446. It can be enabled by adding the value tls13=1 to the GODEBUG environment variable. It will be enabled by default in Go 1.13.
二、Go1.13
发布时间
3 September 2019
版本概要
- The go command now downloads and authenticates modules using the Go module mirror and Go checksum database by default
- Improvements to number literals
- Error wrapping
- TLS 1.3 on by default
- Improved modules support
版本重点内容
1. Changes to the language
supports a more uniform and modernized set of number literal prefixes.
- Binary integer literals: The prefix 0b or 0B indicates a binary integer literal such as 0b1011.
- Octal integer literals: The prefix 0o or 0O indicates an octal integer literal such as 0o660. The existing octal notation indicated by a leading 0 followed by octal digits remains valid.
- Hexadecimal floating point literals: The prefix 0x or 0X may now be used to express the mantissa of a floating-point number in hexadecimal format such as 0x1.0p-1021. A hexadecimal floating-point number must always have an exponent, written as the letter p or P followed by an exponent in decimal. The exponent scales the mantissa by 2 to the power of the exponent.
- Imaginary literals: The imaginary suffix i may now be used with any (binary, decimal, hexadecimal) integer or floating-point literal.
- Digit separators: The digits of any number literal may now be separated (grouped) using underscores, such as in 1_000_000, 0b_1010_0110, or 3.1415_9265. An underscore may appear between any two digits or the literal prefix and the first digit.
- Per the signed shift counts proposal Go 1.13 removes the restriction that a shift count must be unsigned. This change eliminates the need for many artificial uint conversions, solely introduced to satisfy this (now removed) restriction of the << and >> operators.
Tools-Modules
Environment variables
- The new GOPRIVATE environment variable indicates module paths that are not publicly available. It serves as the default value for the lower-level GONOPROXY and GONOSUMDB variables, which provide finer-grained control over which modules are fetched via proxy and verified using the checksum database.
- TheGOPROXYenvironment variablemay now be set to a comma-separated list of proxy URLs or the special tokendirect, and itsdefault valueis nowhttps://proxy.golang.org,direct.
- The new GOSUMDB environment variable identifies the name, and optionally the public key and server URL, of the database to consult for checksums of modules that are not yet listed in the main module's go.sum file. If GOSUMDB does not include an explicit URL, the URL is chosen by probing the GOPROXY URLs for an endpoint indicating support for the checksum database, falling back to a direct connection to the named database if it is not supported by any proxy. If GOSUMDB is set to off, the checksum database is not consulted and only the existing checksums in the go.sum file are verified.
Version validation
When extracting a module from a version control system, the go command now performs additional validation on the requested version string.
- The incompatible version annotation bypasses the requirement of semantic import versioning for repositories that predate the introduction of modules. The go command now verifies that such a version does not include an explicit go.mod file.
- The go command now verifies the mapping between pseudo-versions and version-control metadata. Specifically:
1. The version prefix must be of the form vX.0.0, or derived from a tag on an ancestor of the named revision, or derived from a tag that includes build metadata on the named revision itself.
2. The date string must match the UTC timestamp of the revision.
3. The short name of the revision must use the same number of characters as what the go command would generate. (For SHA-1 hashes as used by git, a 12-digit prefix.)
- replace directive
If one of the transitive dependencies of the main module requires an invalid version or pseudo-version, the invalid version can be replaced with a valid one using a replace directive in the go.mod file of the main module. If the replacement is a commit hash, it will be resolved to the appropriate pseudo-version as above. For example,
replace github.com/docker/docker v1.14.0-0.20190319215453-e7b5f7dbe98c => github.com/docker/docker e7b5f7dbe98c
Runtime
- Out of range panic messages now include the index that was out of bounds and the length (or capacity) of the slice. For example, s[3] on a slice of length 1 will panic with "runtime error: index out of range [3] with length 1".
- This release improves performance of most uses of defer by 30%.
- The runtime is now more aggressive at returning memory to the operating system to make it available to co-tenant applications. Previously, the runtime could retain memory for five or more minutes following a spike in the heap size. It will now begin returning it promptly after the heap shrinks. However, on many OSes, including Linux, the OS itself reclaims memory lazily, so process RSS will not decrease until the system is under memory pressure.
三、Go1.14
发布时间
25 February 2020
版本概要
- Module support in the go command is now ready for production use. We encourage all users to migrate to go modules for dependency management.
- Embedding interfaces with overlapping method sets.
- Improved defer performance.
- Goroutines are asynchronously preemptible.
- The page allocator is more efficient.
- Internal timers are more efficient.
版本重点内容
1. Changes to the language
Go 1.14 now permits embedding of interfaces with overlapping method sets
methods from an embedded interface may have the same names and identical signatures as methods already present in the (embedding) interface. This solves problems that typically (but not exclusively) occur with diamond-shaped embedding graphs. Explicitly declared methods in an interface must remainunique, as before.
2. Tools-Module
vendoring
When the main module contains a top-level vendor directory and its go.mod file specifies go 1.14 or higher, the go command now defaults to -mod=vendor for operations that accept that flag. A new value for that flag, -mod=mod, causes the go command to instead load modules from the module cache (as when no vendor directory is present).
When -mod=vendor is set (explicitly or by default), the go command now verifies that the main module's vendor/modules.txt file is consistent with its go.mod file.
Environment variables
GOINSECURE is a new environment variable that instructs the go command to not require an HTTPS connection, and to skip certificate validation, when fetching certain modules directly from their origins. Like the existing GOPRIVATE variable, the value of GOINSECURE is a comma-separated list of glob patterns.
incompatible versions
If the latest version of a module contains a go.mod file, go get will no longer upgrade to an incompatible major version of that module unless such a version is requested explicitly or is already required. go list also omits incompatible major versions for such a module when fetching directly from version control, but may include them if reported by a proxy.
go.mod file maintenance
go commands other than go mod tidy no longer edit the go.mod file if the changes are only cosmetic.
Module downloading
The go command now supports Subversion repositories in module mode.
3. Runtime
- improves the performance of most uses of defer to incur almost zero overhead compared to calling the deferred function directly. As a result,defercan now be used in performance-critical code without overhead concerns.
- Goroutines are now asynchronously preemptible. As a result, loops without function calls no longer potentially deadlock the scheduler or significantly delay garbage collection. This is supported on all platforms exceptwindows/arm,darwin/arm,js/wasm, andplan9/*.
- Go 1.14 will receive more signals than programs built with earlier releases. This means that programs that use packages likesyscallorgolang.org/x/sys/unixwill see more slow system calls fail withEINTRerrors.
- The page allocator is more efficient and incurs significantly less lock contention at high values of GOMAXPROCS. This is most noticeable as lower latency and higher throughput for large allocations being done in parallel and at a high rate.
- Internal timers, used by time.After, time.Tick, net.Conn.SetDeadline, and friends, are more efficient, with less lock contention and fewer context switches.
四、Go1.15
发布时间
11 August 2020
版本概要
- Substantial improvements to the Go linker
- Improved allocation for small objects at high core counts
- X.509 CommonName deprecation
- GOPROXY supports skipping proxies that return errors
- New embedded tzdata package
- A number of Core Library improvements
版本重点内容
Go command
The GOPROXY environment variable now supports skipping proxies that return errors. Proxy URLs may now be separated with either commas (,) or pipe characters (|). If a proxy URL is followed by a comma, thegocommand will only try the next proxy in the list after a 404 or 410 HTTP response. If a proxy URL is followed by a pipe character, thegocommand will try the next proxy in the list after any error. Note that the default value ofGOPROXYremainshttps://proxy.golang.org,direct, which does not fall back todirectin case of errors.
Module cache
The location of the module cache may now be set with the GOMODCACHE environment variable. The default value of GOMODCACHE is GOPATH[0]/pkg/mod, the location of the module cache before this change.
Vet
The vet tool now warns about conversions of the form string(x) where x has an integer type other than rune or byte. Experience with Go has shown that many conversions of this form erroneously assume that string(x) evaluates to the string representation of the integer x. It actually evaluates to a string containing the UTF-8 encoding of the value of x. For example, string(9786) does not evaluate to the string "9786"; it evaluates to the string "xe2x98xba", or "☺".
The vet tool now warns about type assertions from one interface type to another interface type when the type assertion will always fail. This will happen if both interface types implement a method with the same name but with a different type signature.
Runtime
- If panic is invoked with a value whose type is derived from any of: bool, complex64, complex128, float32, float64, int, int8, int16, int32, int64, string, uint, uint8, uint16, uint32, uint64, uintptr, then the value will be printed, instead of just its address. Previously, this was only true for values of exactly these types.
- Allocation of small objects now performs much better at high core counts, and has lower worst-case latency.
- Converting a small integer value into an interface value no longer causes allocation.
- Non-blocking receives on closed channels now perform as well as non-blocking receives on open channels.
Linker
This release includes substantial improvements to the Go linker, which reduce linker resource usage (both time and memory) and improve code robustness/maintainability.
For a representative set of large Go programs, linking is 20% faster and requires 30% less memory on average, for ELF-based OSes (Linux, FreeBSD, NetBSD, OpenBSD, Dragonfly, and Solaris) running on amd64 architectures, with more modest improvements for other architecture/OS combinations.
Core library
New embedded tzdata package
Go 1.15 includes a new package, time/tzdata, that permits embedding the timezone database into a program. Importing this package (as import _ "time/tzdata") permits the program to find timezone information even if the timezone database is not available on the local system. You can also embed the timezone database by building with -tags timetzdata. Either approach increases the size of the program by about 800 KB.
X.509 CommonName deprecation
The deprecated, legacy behavior of treating the CommonName field on X.509 certificates as a host name when no Subject Alternative Names are present is now disabled by default. It can be temporarily re-enabled by adding the value x509ignoreCN=0 to the GODEBUG environment variable.
Note that if the CommonName is an invalid host name, it's always ignored, regardless of GODEBUG settings. Invalid names include those with any characters other than letters, digits, hyphens and underscores, and those with empty labels or trailing dots.
下一篇文章会继续整理Go16-20版本的变更。