Stable Release in branch 1.22
1.22.12
Released 04 Feb 2025
(1 year ago)
SoftwareGo
Version1.22
Status
End of life
Initial release1.22.0
06 Feb 2024
(2 years ago)
Latest release1.22.12
04 Feb 2025
(1 year ago)
End of life11 Feb 2025
(Ended 1 year ago)
Release noteshttps://go.dev/doc/go1.22
Source codehttps://github.com/golang/go/tree/go1.22.12
Documentationhttps://go.dev/doc/
Go 1.22 ReleasesView full list

What Is New in Go 1.22

Category Key Changes
Language Range-over-function experiments, range-over-integer support
Standard Library Enhanced HTTP routing, new math/rand/v2 package, database/sql improvements
Tooling Improved loop variable capture, better program counter alignment
Performance Faster stack growth, optimized compiler, PGO enhancements
Security More secure randomness, vet improvements for loops and time formats

What language changes should I know about?

Go 1.22 introduces range-over-integer support, letting you write cleaner loops. Instead of the traditional for i := 0; i < 10; i++, you can now use for i := range 10 for simpler iteration.

The most significant change affects loop variable capture. Previously, loop variables had a single address shared across iterations, causing bugs in goroutines. Now, each iteration gets its own variable, making concurrent loops much safer.

There's also an experimental range-over-functions feature, but this requires enabling with GOEXPERIMENT=rangefunc. This explores new ways to iterate but isn't production-ready yet.

How does HTTP routing improve in 1.22?

The net/http package now supports enhanced pattern matching in ServeMux. You can use methods like POST /items/{id} and wildcards like /files/{path...} directly without third-party routers.

This means you can write RESTful APIs with path parameters natively. The router now matches methods specifically and validates patterns at registration time, catching errors early.

In practice, this reduces dependency on external routing libraries for many common use cases. The built-in router now handles most basic API routing needs effectively.

What's new with math/rand/v2?

Go 1.22 introduces math/rand/v2 with cleaner APIs and better algorithms. The new package fixes several design warts from the original, like unclear method names and inconsistent behavior.

It uses a higher-quality random number generator by default and provides new methods like N for generating random integers within a range. The original math/rand remains available for backward compatibility.

This matters because the v2 package offers both performance improvements and more predictable behavior. For new code, you should prefer the v2 package whenever possible.

What tooling improvements help developers?

The go vet tool now detects more potential bugs, including invalid time formats in time.Format calls. It also checks for accidental shadowing of loop variables before the new semantics.

Profile-guided optimization (PGO) can now handle larger profiles and delivers better optimizations. The compiler uses PGO information more effectively to inline functions and optimize code paths.

Stack growth has been optimized to reduce overhead, particularly for small stacks. This improves performance in goroutine-heavy applications without changing your code.

How does database/sql get better?

The database/sql package now supports named parameters and retries for connection attempts. You can use :name placeholders instead of just ? in your SQL queries.

Connection pool handling is more robust with better error recovery. The package will automatically retry failed connection attempts when appropriate, making applications more resilient.

These changes simplify working with complex queries and improve reliability in distributed database environments. The named parameters especially help with readability of SQL code.

FAQ

Will the loop variable change break my existing code?
Yes, but intentionally. The change fixes a common bug where goroutines in loops would capture the same variable. Your code might behave differently now, but more correctly. The old behavior was considered buggy.

Should I use math/rand or math/rand/v2 for new projects?
Use math/rand/v2 for new code. It has better APIs, improved performance, and more predictable behavior. The original package remains for compatibility but won't receive new features.

Can I use the new HTTP routing patterns with existing code?
Yes, the enhanced ServeMux is backward compatible. Existing patterns continue to work, but you can gradually adopt the new method-specific and wildcard patterns in your routes.

How do I try the range-over-functions experiment?
Set GOEXPERIMENT=rangefunc in your environment before building. Remember this is experimental and might change or be removed in future versions, so don't use it in production.

Does the database/sql named parameter support work with all drivers?
No, driver support is required. The feature works with drivers that implement the new NamedValueChecker interface. Check your driver's documentation for compatibility.

Releases In Branch 1.22

VersionRelease date
1.22.1204 Feb 2025
(1 year ago)
1.22.1116 Jan 2025
(1 year ago)
1.22.1003 Dec 2024
(1 year ago)
1.22.906 Nov 2024
(1 year ago)
1.22.801 Oct 2024
(1 year ago)
1.22.705 Sep 2024
(1 year ago)
1.22.606 Aug 2024
(2 years ago)
1.22.502 Jul 2024
(2 years ago)
1.22.404 Jun 2024
(2 years ago)
1.22.307 May 2024
(2 years ago)
1.22.203 Apr 2024
(2 years ago)
1.22.105 Mar 2024
(2 years ago)
1.22.006 Feb 2024
(2 years ago)
1.22rc224 Jan 2024
(2 years ago)
1.22rc119 Dec 2023
(2 years ago)