agentleFS
RoninForgeRoninForge/roninforge-go/skills/go-modernize/SKILL.md

go-modernize

Skill0 starsChanged 7 months agoMITView on GitHub

Migrate older Go code to 1.22+ idioms: ioutil -> io/os, log.Println -> slog, interface{} -> any, manual mux routing -> http.ServeMux method patterns, drop v := v shadow, math/rand -> math/rand/v2.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. eduardo-sl/go-agent-skills★ 72same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository3 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When inheriting or auditing a Go codebase that predates 1.22 patterns, or when an AI-generated codebase uses outdated idioms.

    line 10
  2. Very specific:

    If the codebase has a hand-rolled router or third-party (mux.Router, chi.Router) and the routing is simple, port to stdlib:

    line 76
  3. Distinctive:

    If the project uses middleware chains or wildcards, leave the existing router and apply other rules.

    line 88
  4. Distinctive:

    Remove the shadow line.

    line 98
  5. Very specific:

    Never use math/rand for security-sensitive randomness.

    line 121
  6. Very specific:

    Use the go-error-wrap skill for this step.

    line 125
  7. Very specific:

    If a third-party linter is available, also run golangci-lint run.

    line 137

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Modernize Go to 1.22+

When to Use

When inheriting or auditing a Go codebase that predates 1.22 patterns, or when an AI-generated codebase uses outdated idioms.

Instructions

Apply each transformation in order. Run go build ./... and go test ./... after each step.

Step 1: Bump Go version

In go.mod:

go 1.24

Set this to the lowest version the project will support. go 1.22 minimum for the patterns in this skill.

Step 2: ioutil -> io / os

grep -rln 'io/ioutil' --include='*.go' .

Replace:

  • ioutil.ReadAll(r) -> io.ReadAll(r)
  • ioutil.ReadFile(p) -> os.ReadFile(p)
  • ioutil.WriteFile(p, b, mode) -> os.WriteFile(p, b, mode)
  • ioutil.TempFile(...) -> os.CreateTemp(...)
  • ioutil.TempDir(...) -> os.MkdirTemp(...)
  • ioutil.NopCloser(r) -> io.NopCloser(r)
  • ioutil.Discard -> io.Discard

Then remove the import.

Step 3: interface{} -> any

grep -rln 'interface{}' --include='*.go' . | xargs sed -i.bak 's/interface{}/any/g'

Review each change. interface{} may legitimately appear in generated code; do not touch generated files (*_gen.go, *.pb.go).

Step 4: log -> slog

Replace package-level log calls:

// before
log.Printf("user %s logged in", id)
log.Fatal("db connect:", err)

// after
slog.InfoContext(ctx, "user login", "user_id", id)
return fmt.Errorf("db connect: %w", err)  // and exit non-zero from main

At the top of main:

logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
slog.SetDefault(logger)

log.Fatal is the worst offender - it calls os.Exit(1) which skips deferred funcs. Always replace with a returned error.

Step 5: Routing -> http.ServeMux method patterns (1.22+)

If the codebase has a hand-rolled router or third-party (mux.Router, chi.Router) and the routing is simple, port to stdlib:

mux := http.NewServeMux()
mux.HandleFunc("GET /users/{id}", h.GetUser)
mux.HandleFunc("POST /users", h.CreateUser)
mux.HandleFunc("DELETE /users/{id}", h.DeleteUser)

// in handler
id := r.PathValue("id")

If the project uses middleware chains or wildcards, leave the existing router and apply other rules.

Step 6: Drop unnecessary loop-variable shadowing

In 1.22+, for _, v := range items creates a fresh v each iteration. The v := v shadow is unnecessary.

grep -rnE '^\s*[a-z]+ := [a-z]+\s*$' --include='*.go' . -B 2 | grep 'for .* range'

Remove the shadow line.

Step 7: math/rand -> math/rand/v2

For non-cryptographic randomness:

// before
import "math/rand"
n := rand.Intn(100)

// after
import "math/rand/v2"
n := rand.IntN(100)

For cryptographic randomness (tokens, passwords, IDs), use crypto/rand:

import "crypto/rand"
token := rand.Text()  // 1.24+, returns base32 26-char string

Never use math/rand for security-sensitive randomness.

Step 8: Error wrapping

Use the go-error-wrap skill for this step.

Step 9: Verify

go mod tidy
go build ./...
go vet ./...
staticcheck ./...
go test -race ./...

If a third-party linter is available, also run golangci-lint run.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.