SKILL·E35BFE

go-modernize

eduardo-sl
Aktualisiert 27 days ago
5 Ansichten
70
9
70
Auf GitHub ansehen
Entwicklunggeneral

Über

Diese Fähigkeit modernisiert Go-Code, indem sie ihn an neuere Sprachfeatures von Go 1.21-1.23+ anpasst, einschließlich Generics, log/slog, errors.Join und den Paketen slices/maps. Verwenden Sie sie gezielt, wenn Sie Legacy-Muster wie `interface{}` refaktorieren oder Features wie Range-over-Func und Iteratoren übernehmen möchten. Sie ist nicht für allgemeine Stilfragen, Fehlerphilosophie oder Logging-Architektur gedacht – nutzen Sie dafür andere spezialisierte Fähigkeiten.

Schnellinstallation

Claude Code

Empfohlen
Primär
npx skills add eduardo-sl/go-agent-skills -a claude-code
Plugin-BefehlAlternativ
/plugin add https://github.com/eduardo-sl/go-agent-skills
Git CloneAlternativ
git clone https://github.com/eduardo-sl/go-agent-skills.git ~/.claude/skills/go-modernize

Kopieren Sie diesen Befehl und fügen Sie ihn in Claude Code ein, um diese Fähigkeit zu installieren

Dokumentation

Go Modernize

Go evolves. Code written for Go 1.16 should not look the same as code targeting Go 1.22+. Modernize incrementally — update go.mod, then adopt new patterns.

Detailed reference material, loaded on demand:

  • references/generics.md — replacing interface{} with type parameters, constraints, generic containers, when NOT to use generics.
  • references/stdlib-migrations.md — before/after examples for slog, errors.Join, slices/maps helpers, range-over-int, and iterators.

Read a reference file only when the summary below is not enough.

Modernization Procedure

  1. Check the go directive in go.mod — it caps which features you can use.

  2. Run the official modernize analyzer first — it finds and fixes the mechanical migrations automatically:

    go run golang.org/x/tools/gopls/internal/analysis/modernize/cmd/modernize@latest -fix -test ./...
    

    If the command is unavailable in your environment, apply the table below manually instead.

  3. Scan the table below for the judgment-based migrations the analyzer does not cover (generics, iterators, logger replacement) and apply them case by case.

  4. Run go build ./... and the test suite after each group of changes.

Feature Table by Go Version

Go VersionFeatureAction
1.13+errors.Is, errors.AsReplace == error comparisons
1.13+http.NewRequestWithContextReplace http.NewRequest
1.16+embedReplace go-bindata / packr
1.18+GenericsReplace interface{} utility functions
1.20+errors.JoinReplace manual error accumulation
1.21+log/slogReplace log for structured logging
1.21+slices, mapsReplace hand-written slice/map utilities
1.21+min, max builtinsReplace math.Min/math.Max (float64-only)
1.22+Range over intReplace for i := 0; i < n; i++
1.23+Range over funcReplace callback-based iteration

Key Migrations at a Glance

Generics — type-safe utilities (Go 1.18+)

// ❌ Before — loses type safety
func Contains(slice []interface{}, target interface{}) bool { /* ... */ }

// ✅ After — type-safe generic
func Contains[T comparable](slice []T, target T) bool { /* ... */ }

Use generics for container types (Set[T], Result[T]) and utility functions. Do NOT use them where a single concrete type works, or as a substitute for interfaces in runtime polymorphism. Details and constraint patterns: references/generics.md.

Structured logging (Go 1.21+)

// ❌ Before
log.Printf("processing order %s for user %s", orderID, userID)

// ✅ After
slog.Info("processing order",
    slog.String("order_id", orderID),
    slog.String("user_id", userID),
)

Keep zap/zerolog only if you need their performance for high-throughput logging; for most services slog is sufficient.

errors.Join (Go 1.20+)

var errs []error
for _, item := range items {
    if err := validate(item); err != nil {
        errs = append(errs, err)
    }
}
if err := errors.Join(errs...); err != nil {
    return fmt.Errorf("validation: %w", err)
}

errors.Join preserves the chain — errors.Is/errors.As work on each joined error. Never accumulate error strings manually.

slices and maps helpers (Go 1.21+)

found := slices.Contains(items, target)          // not a manual loop
slices.SortFunc(users, func(a, b User) int {     // not sort.Slice
    return cmp.Compare(a.Name, b.Name)
})
keys := slices.Collect(maps.Keys(m))             // not a manual key loop
clone := maps.Clone(m)                           // not a manual copy loop

Range over int (Go 1.22+) and iterators (Go 1.23+)

for i := range n { process(i) }                  // not for i := 0; i < n; i++

for i, v := range slices.Backward(items) {       // stdlib iterators
    fmt.Printf("%d: %v\n", i, v)
}

Custom iter.Seq/iter.Seq2 iterators replace callback-based iteration — full worked example in references/stdlib-migrations.md.

Context-aware HTTP requests (Go 1.13+, often missed)

// ❌ Before — request without context
req, err := http.NewRequest(http.MethodGet, url, nil)

// ✅ After — context propagated
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)

Verification Checklist

  1. go.mod version matches the features used in the codebase
  2. No interface{} where any or type parameters would be clearer
  3. log/slog used instead of log.Printf for structured logging
  4. errors.Join used instead of manual error string concatenation
  5. slices.Contains, slices.SortFunc, maps.Clone replace hand-written loops
  6. Range over int (for i := range n) used where applicable
  7. http.NewRequestWithContext used instead of http.NewRequest
  8. No sort.Slice — use slices.SortFunc with cmp.Compare
  9. Generics used for type-safe containers and utilities, not overused for trivial cases
  10. Third-party dependencies evaluated against stdlib alternatives added in recent Go versions

GitHub Repository

eduardo-sl/go-agent-skills
Pfad: skills/(code-quality)/go-modernize
0
FAQ

Häufig gestellte Fragen

Was ist der Skill go-modernize?

go-modernize ist ein Claude Skill von eduardo-sl. Skills bündeln Anweisungen und Ressourcen, die Claude bei Bedarf lädt, um Aufgaben rund um go-modernize ohne zusätzliche Eingaben auszuführen.

Wie installiere ich go-modernize?

Verwende die Installationsbefehle auf dieser Seite: Füge go-modernize als Plugin zu Claude Code hinzu oder klone das Repository in dein Skills-Verzeichnis. Starte Claude danach neu, damit der Skill geladen wird.

Zu welcher Kategorie gehört go-modernize?

go-modernize gehört zur Kategorie Entwicklung.

Kann ich go-modernize kostenlos nutzen?

Ja. go-modernize ist auf AIMCP gelistet und kann kostenlos installiert werden.

Verwandte Skills

qmd
Entwicklung

qmd ist ein lokales Such- und Indexierungs-CLI-Tool, das Entwicklern ermöglicht, lokale Dateien mittels Hybridsuche zu indexieren und zu durchsuchen, die BM25, Vektoreinbettungen und Neuordnung kombiniert. Es unterstützt sowohl die Kommandozeilennutzung als auch den MCP-Modus (Model Context Protocol) zur Integration mit Claude. Das Tool verwendet Ollama für Einbettungen und speichert Indizes lokal, was es ideal für die direkte Suche in Dokumentationen oder Codebasen vom Terminal aus macht.

Skill ansehen
subagent-driven-development
Entwicklung

Diese Fähigkeit führt Implementierungspläne aus, indem für jede unabhängige Aufgabe ein neuer Subagent bereitgestellt wird, mit Code-Review zwischen den Aufgaben. Sie ermöglicht schnelle Iterationen, während Qualitätssicherungsschritte durch diesen Review-Prozess gewahrt bleiben. Nutzen Sie sie, wenn Sie überwiegend unabhängige Aufgaben innerhalb derselben Sitzung bearbeiten, um kontinuierlichen Fortschritt mit integrierten Qualitätsprüfungen zu gewährleisten.

Skill ansehen
mcporter
Entwicklung

Die mcporter-Skill ermöglicht es Entwicklern, Model Context Protocol (MCP)-Server direkt aus Claude heraus zu verwalten und aufzurufen. Sie bietet Befehle, um verfügbare Server aufzulisten, deren Tools mit Argumenten aufzurufen sowie Authentifizierung und Daemon-Lebenszyklus zu handhaben. Nutzen Sie diese Skill, um MCP-Server-Funktionalität in Ihren Entwicklungs-Workflow zu integrieren und zu testen.

Skill ansehen
adk-deployment-specialist
Entwicklung

Diese Fähigkeit stellt Vertex AI ADK-Agenten über das A2A-Protokoll bereit und orchestriert sie, verwaltet die AgentCard-Erkennung, Aufgabenübermittlung und unterstützende Tools wie die Code Execution Sandbox und Memory Bank. Sie ermöglicht den Aufbau von Multi-Agenten-Systemen mit sequenziellen, parallelen oder Schleifen-Orchestrierungsmustern in Python, Java oder Go. Verwenden Sie sie, wenn Sie aufgefordert werden, ADK-Agenten bereitzustellen oder Agenten-Workflows auf Google Cloud zu orchestrieren.

Skill ansehen