What is new in Go 1.22?
While finishing the writing of this book, Go 1.22 was officially released. In this section, we are going to present the most interesting new features and improvements of Go 1.22.
- There is no more sharing in the variables of loops.
- Functions that shrink the size of a slice (
Delete()
,DeleteFunc()
,Compact()
,CompactFunc()
, andReplace()
) now zero the elements between the new length and the old length. - There is an updated version of
math/rand
, which is calledmath/rand/v2
.
Keep in mind that in Go 1.22 the HTTP routing capabilities of the standard library are improved. In practice, this means that the patterns used by net/http.ServeMux
have been enhanced to accept methods and wildcards. You can find more about that at https://pkg.go.dev/net/http@master#ServeMux.
We’ll begin by presenting the changes in the slices
package.
Changes in slices
Apart from the changes in the functions that shrink the size of a slice...