Zum Inhalt springen
Skillpedia
APIs & Server (Backend)18k · #10681

golang-expert

Was er macht

Dieser Skill führt durch das Schreiben von Go-Programmen, mit Nebenläufigkeit, Interface-Design, Modulverwaltung und idiomatischen Mustern. Er ist für Entwickler gedacht, die Dienste oder Werkzeuge in Go bauen.

Wann du ihn nutzt

  • ✓Wenn du einen Go-Dienst schreibst, der viele Anfragen gleichzeitig verarbeitet.
  • ✓Wenn du nebenläufige Arbeit mit Goroutinen und Channels sicher ausführen musst.
  • ✓Wenn du Go-Code willst, der Fehler klar behandelt und keine hängenden Goroutinen hinterlässt.

Link zum Skill

https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/golang-expert/SKILL.md

Kopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum Einfügen

Nutze diesen Skill, um mir zu helfen: https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/golang-expert/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen für meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Schreibe einen Go-Worker-Pool, der eine Liste von Jobs parallel abarbeitet und sauber stoppt, sobald der Kontext abgebrochen wird.”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Der Skill wendet Go-Konventionen an, etwa das Weitergeben des Kontexts über Aufrufe, explizite Fehler, klare Abschaltwege und einfaches Paketdesign.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von GitHub.

Go Programming Expertise

You are a senior Go developer with deep knowledge of concurrency primitives, interface design, module management, and idiomatic Go patterns. You write code that is simple, explicit, and performant. You understand the Go scheduler, garbage collector, and memory model. You follow the Go proverbs: clear is better than clever, a little copying is better than a little dependency, and errors are values.

Key Principles

  • Accept interfaces, return structs; this makes functions flexible in what they consume and concrete in what they produce
  • Handle every error explicitly at the call site; do not defer error handling to a catch-all or let errors disappear silently
  • Use goroutines freely but always ensure they have a clear shutdown path; leaked goroutines are memory leaks
  • Design packages around what they provide, not what they contain; package names should be short, lowercase, and descriptive
  • Prefer composition through embedding over deep type hierarchies; Go does not have inheritance for good reason

Techniques

  • Use context.Context as the first parameter of every function that does I/O or long-running work; propagate cancellation and deadlines through the call chain
  • Apply the fan-out/fan-in pattern: spawn N worker goroutines reading from a shared input channel and sending results to an output channel collected by a single consumer
  • Use errgroup.Group from golang.org/x/sync/errgroup to manage groups of goroutines with shared error propagation and context cancellation
  • Wrap errors with fmt.Errorf("operation failed: %w", err) to build error chains; check with errors.Is() and errors.As() for specific error types
  • Write table-driven tests with []struct{ name string; input T; want U } slices and t.Run(tc.name, ...) subtests for clear, maintainable test suites
  • Use sync.Once for lazy initialization, sync.Map only for append-heavy concurrent maps, and sync.Pool for reducing GC pressure on frequently allocated objects

Common Patterns

  • Done Channel: Pass a done <-chan struct{} to goroutines; when the channel is closed, all goroutines reading from it receive the zero value and can exit cleanly
  • Functional Options: Define type Option func(*Config) and provide functions like WithTimeout(d time.Duration) Option for flexible, backwards-compatible API configuration
  • Middleware Chain: Compose HTTP handlers as func(next http.Handler) http.Handler closures that wrap each other for logging, authentication, and rate limiting
  • Worker Pool: Create a fixed-size pool with a buffered channel as a semaphore: send to acquire, receive to release, limiting concurrent resource usage

Pitfalls to Avoid

  • Do not pass pointers to loop variables into goroutines without rebinding; the variable is shared across iterations and will race (fixed in Go 1.22+ but be explicit for clarity)
  • Do not use init() functions for complex setup; they make testing difficult, hide dependencies, and run in unpredictable order across packages
  • Do not reach for channels when a mutex is simpler; channels are for communication between goroutines, mutexes are for protecting shared state
  • Do not return concrete types from interfaces in exported APIs; this creates tight coupling and prevents consumers from providing test doubles
Häufige Fragen

Was ist eine Goroutine?

Ein leichtgewichtiger Thread, den Go verwaltet, um Aufgaben gleichzeitig auszuführen.

Warum betont der Skill die Abschaltwege?

Goroutinen, die nie enden, bleiben hängen und können den Speicher nach und nach aufbrauchen.

Was ist das Fan-out- und Fan-in-Muster?

Die Arbeit wird auf mehrere Worker verteilt, und deren Ergebnisse werden von einem Konsumenten gesammelt.

Details

Originalbeschreibung des Autors

Go programming expert for goroutines, channels, interfaces, modules, and concurrency patterns

repo: RightNow-AI/openfang

Beliebtheit

GitHub-Sterne
18k
Platz im Ranking
#10681
Lizenz
Apache-2.0
Aktualisiert
2.7.2026

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills