What Is New in Go 1.13
Go 1.13 brings a set of focused improvements to the toolchain, runtime, and core libraries. The changes enhance number literal readability, error handling, and module support.
| Category | Key Changes |
|---|---|
| Language | New number literals, error wrapping, aligned panic semantics |
| Tools | GOPROXY fallback, GOSUMDB, module fetching enhancements |
| Runtime & Compiler | More efficient defer, TLS management, heap allocation optimizations |
| Core Library | New errors package, crypto/tls improvements, sync.Pool victim cache |
What language changes were introduced?
Go 1.13 added syntax features for better code clarity and error handling. The changes are minimal but practical for everyday development.
Number Literals
You can now use underscores as separators in number literals for improved readability. This works for binary, octal, and hexadecimal values.
v := 0b_0010_0101 // Binary with underscores
w := 1_000_000 // Decimal
x := 0x_FF_FF // Hexadecimal
Error Wrapping
The language now supports error wrapping with the %w verb for fmt.Errorf. This creates nested errors that can be unwrapped later.
if err != nil {
return fmt.Errorf("operation failed: %w", err)
}
How did the toolchain and modules improve?
The Go toolchain got smarter about dependency management and proxy handling. These changes make module workflows more robust in various network environments.
The GOPROXY environment variable now supports a comma-separated list of proxies and the keyword direct. If a proxy fails, the tool will fall back to the next option or direct source control.
GOPROXY="https://proxy.golang.org,direct"
A new GOSUMDB environment variable specifies which database to use for checksum verification. This adds a layer of security for ensuring downloaded modules haven't been tampered with.
What performance optimizations were made?
The runtime and compiler received targeted optimizations that reduce overhead for common operations. You'll see the most benefit in applications using many defers or sync.Pool.
The defer statement is now more efficient, with significantly reduced overhead compared to previous versions. This matters because it makes using defers in performance-critical code less costly.
sync.Pool now uses a victim cache mechanism. This helps reduce lock contention and improves performance under high garbage collection pressure, which is common in web servers.
What's new in the standard library?
Key packages like errors, crypto/tls, and net received important updates. These changes provide better functionality without breaking existing code.
Errors Package
The new errors package includes functions Is, As, and Unwrap for working with wrapped errors. This formalizes the pattern introduced with error wrapping.
if errors.Is(err, os.ErrNotExist) {
// Handle the specific error type
}
TLS 1.3
The crypto/tls package now supports TLS 1.3, which is enabled by default for both clients and servers. This provides better security and performance for encrypted connections.
FAQ
Does error wrapping with %w break existing error handling?
No, it's fully backward compatible. Existing error checks continue to work. The new errors.Is and errors.As functions are for inspecting the chain of wrapped errors.
How do the new number literals affect parsing?
Underscores in numbers are purely for readability and are ignored by the parser. The actual value remains unchanged, so there's no impact on existing code or data.
Is TLS 1.3 now the default?
Yes, TLS 1.3 is enabled by default in crypto/tls for both clients and servers. The implementation is interoperable with other TLS 1.3 implementations.
What happens if my GOPROXY is down?
With the new fallback mechanism, the go command will try the next proxy in the list or connect directly to version control systems if you include "direct" in your GOPROXY setting.
Do I need to change my code to benefit from the defer optimizations?
No, the improved performance for defer statements is automatic. All existing code using defer will run faster without any modifications.