# Go 1 22

> Apply Go 1.22 language features, tooling, standard-library APIs, migrations, and behaviour changes. Load for Go work targeting 1.22 or later when the model's knowledge may predate the 2024-02-06 release.

- Skill: `cedws/go-1-22` (Agent Skill)
- Install (CLI): `npx skillmds@latest add cedws/go-1-22`
- Raw SKILL.md: https://api.skillmd.com/api/skills/cedws/go-1-22/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: cedws (https://skillmd.com/u/cedws)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/cedws/go-1-22

---


# Go 1.22

This overview applies when the project's target Go version is at least 1.22.

## Language

- Loop variables declared by a `for` loop are distinct for every iteration, making defensive shadow assignments for closures and goroutines unnecessary.
- Integer ranges iterate from zero to one less than a bound.

```go
for index := range count {
	process(index)
}
```

- `GOEXPERIMENT=rangefunc` enables a preview of range-over-function iterators; it is not a stable Go 1.22 language feature.

## Tools and workspaces

- `go work vendor` creates a shared vendor directory for a multi-module workspace; that directory cannot simultaneously represent single-module vendoring state.
- `go get` no longer works in legacy `GOPATH` mode, so dependency changes occur inside modules.
- `go test -cover` reports zero coverage for packages containing executable code but no tests.
- `go vet` detects ineffective `append` calls, prematurely evaluated `time.Since` calls in `defer`, and malformed alternating key-value arguments to `log/slog`.
- The refreshed execution tracer supports streamable traces, complete system-call durations, and correlation with operating-system clocks. `GOEXPERIMENT=noexectracer2` restores the older tracer temporarily.

## Randomness and versions

- `math/rand/v2` is the modern non-cryptographic random-number API, with `IntN`, `UintN`, generic `N`, and the PCG and ChaCha8 sources for local state.
- `crypto/rand.Read` remains the API for random bytes that protect secrets; `math/rand/v2` is not a substitute.
- `go/version` validates and compares Go version strings without ad hoc parsing.

## HTTP routing and filesystems

- `http.ServeMux` patterns can include HTTP methods and wildcards, with wildcard values available through `Request.PathValue`.

```go
mux.HandleFunc("GET /items/{id}", func(writer http.ResponseWriter, request *http.Request) {
	id := request.PathValue("id")
	serveItem(writer, request, id)
})
```

- Braces, escaped paths, and conflicting patterns can behave differently under the new routing semantics; `GODEBUG=httpmuxgo121=1` temporarily restores the old behaviour.
- `http.ServeFileFS`, `http.FileServerFS`, and `http.NewFileTransportFS` serve content from an `fs.FS`.
- `archive/tar.Writer.AddFS` and `archive/zip.Writer.AddFS` add an `fs.FS` without a manual walk.

## Standard library and runtime

- `cmp.Or` selects the first non-zero value in an ordered fallback sequence.
- `slices.Concat` concatenates multiple slices. `Delete`, `DeleteFunc`, `Compact`, `CompactFunc`, and `Replace` now zero obsolete elements.
- `reflect.TypeFor[T]()` replaces the `reflect.TypeOf((*T)(nil)).Elem()` idiom, and `reflect.PointerTo` replaces deprecated `reflect.PtrTo`.
- `/sched/pauses/total/gc:seconds` replaces the deprecated `/gc/pauses:seconds` metric, with additional histograms separating stop coordination from complete pauses.
- `go/types` can expose alias nodes under `GODEBUG=gotypesalias=1`, so named-looking types are not necessarily `*types.Named`.

## Security and compatibility

- TLS servers with no explicit minimum require TLS 1.2, and pre-TLS 1.3 defaults exclude non-ECDHE cipher suites. `tls10server=1` and `tlsrsakex=1` provide temporary legacy compatibility.
- `CertPool.AddCertWithConstraint` associates additional chain-building checks with a custom trust root.
- `slices.Insert` panics for every out-of-range insertion index, including when no values are inserted.

