Go 1.26
This overview applies when the project's target Go version is at least 1.26.
Language
new(expression)is available when an API needs a pointer to an initial value, especially for optional serialization fields. Prefer it to a temporary variable whose only purpose is taking an address.- Available capability: self-referential generic constraints when an operation must accept and return the concrete implementing type.
type Adder[A Adder[A]] interface {
Add(A) A
}
Tools and modules
go fixcan apply behaviour-preserving modernisers for current language and standard-library idioms. Use//go:fix inlinedirectives when maintaining an API whose callers need a source-level migration.- After
go mod init, set the intended compatibility explicitly when it differs from the generated default. A Go 1.26 toolchain initially writesgo 1.25.0. - Replacement:
go tool docwithgo doc; the former has been removed. pprof -httpopens in flame-graph view; the graph view remains selectable explicitly.
Runtime and diagnostics
- Available capability: the Green Tea garbage collector as the default. Enable
GOEXPERIMENT=nogreenteagconly as a temporary diagnostic opt-out and report behaviour or performance regressions. GOEXPERIMENT=goroutineleakprofileenables investigate unreachable, permanently blocked goroutines. Inspect thegoroutineleakprofile throughruntime/pprofor/debug/pprof/goroutineleak, and account for its reachability-based detection limits.- 64-bit heap base randomisation is enabled.
GOEXPERIMENT=norandomizedheapbase64provides a diagnostic opt-out.
Standard library
crypto/hpkesupports RFC 9180 Hybrid Public Key Encryption, including supported post-quantum hybrid KEMs.errors.AsType[T]is the modern alternative toerrors.Asin most typed error extraction because it is type-safe and avoids an output pointer.bytes.Buffer.Peekcan inspect buffered bytes without advancing the buffer.log/slog.NewMultiHandleris available when one record must be dispatched to several handlers while preserving each handler'sEnableddecision.- Available capability: the context-aware
net.Dialer.DialIP,DialTCP,DialUDP, andDialUnixmethods when a concrete network type is required. - Established API:
http.Transport.RoundTripfor managed connection pooling. UseTransport.NewClientConnonly when implementing custom connection management. - Replacement:
httputil.ReverseProxy.DirectorwithReverseProxy.Rewrite;Directoris deprecated because clients can remove headers it adds through hop-by-hop header declarations. - Available capability: the new
reflectfield, method, input, and output iterators instead of index loops when iterating reflection metadata or values.
Cryptography
- Unsupported or discouraged: inject randomness through the reader parameters of affected
crypto/dsa,crypto/ecdh,crypto/ecdsa,crypto/rand, orcrypto/rsaoperations; Go 1.26 ignores them and uses a secure global source. testing/cryptotest.SetGlobalRandomsupports deterministic cryptographic tests. TreatGODEBUG=cryptocustomrand=1as temporary migration support.- Migration note: away from the deprecated
big.Intfields of ECDSA keys and from deprecated RSA PKCS #1 v1.5 encryption. Prefer modern key APIs and OAEP-based encryption. - The hybrid
SecP256r1MLKEM768andSecP384r1MLKEM1024TLS key exchanges are enabled by default.Config.CurvePreferencesexpresses an explicit protocol policy.
Testing
- Test artefact support: persistent test output through
T.ArtifactDir,B.ArtifactDir, orF.ArtifactDir, and rungo test -artifactswhen the artefacts must survive the test process. for b.Loop() { ... }is the modern alternative tofor i := 0; i < b.N; i++ { ... }; Go 1.26 permits inlining in the loop body while retaining benchmark work against elimination.
Experimental features
- Experimental or compatibility option:
GOEXPERIMENT=simdonly for architecture-specific amd64 SIMD evaluation. Treatsimd/archsimdas unstable and non-portable. - Experimental or compatibility option:
GOEXPERIMENT=runtimesecretonly on Linux amd64 or arm64 when evaluating secure erasure of cryptographic temporaries. Treat the API as unstable.
Compatibility
- Unsupported or discouraged: compare JPEG encoder output bit-for-bit across the upgrade; the encoder and decoder implementations changed.
ServeMuxtrailing-slash redirects now use status 307, and thatnet/url.Parserejects malformed host colons. UseGODEBUG=urlstrictcolons=0only while migrating malformed inputs.- Compatibility outlook: for Go 1.27 to remove compatibility switches for older TLS defaults,
go/typesalias representation, and asynchronous timer channels. - Platform requirement: macOS 12 or later, plan to require macOS 13 with Go 1.27, and remove any
windows/armbuild target.