Frameworks, build tools, and HTTP libraries follow the project; do not specify them in this skill.
Do not write APIs from training data. First determine the language version, then read the corresponding reference.
Determine version
- Read the
go.modingoline(language version). Do not use the localgo versionas the language version. When there isgo.work, also read thegoline in it. - When there is
toolchain: the toolchain may be updated,syntax and std APIs are still constrained by thegoline。go 1.24+toolchain go1.26.xstill write per 1.24, do not usenew(expr)。 - Take 1.y(
go 1.25.2→1.25), open the file in the table below, and write code according to that file. Single-file//go:build go1.xxonly raises that file.
| 1.y | File |
|---|---|
| 1.24 | references/1.24.md |
| 1.25 | references/1.25.md |
| 1.26 | references/1.26.md |
| 1.27 | references/1.27.md |
Unlisted newer 1.y: use the highest covered level as the base, then check the official https://go.dev/doc/go1.N . Older: do not use the new APIs in this skill.
Hard rules (1.24+)
- Use
for i := range nfor integer loops; usefor x := range seqto iterate iterators. Do not treatfor i := 0; i < n; i++as the default. - Use
fmt.Errorf("...: %w", err)/errors.Joinfor errors. Do not concatenate witherr.Error()and thenerrors.New。 - Table-driven tests:
tests := []struct{ name string; ... }{...}+t.Run(tt.name, ...)。 - Do not pull in duplicate implementations of capabilities the standard library already has (especially
crypto/*、testing、iter). First search thepkg.go.devpackage documentation for the current language version.