Aller au contenu
Skillpedia
API et serveurs (backend)18k · #10681

golang-expert

Ce qu’il fait

Cette skill guide l'écriture de programmes Go, couvrant la concurrence, la conception des interfaces, la gestion des modules et les motifs idiomatiques. Elle s'adresse aux développeurs qui créent des services ou des outils en Go.

Quand l’utiliser

  • ✓Quand vous écrivez un service Go qui traite de nombreuses requêtes en même temps.
  • ✓Lorsque vous devez exécuter des tâches concurrentes avec des goroutines et des canaux en toute sécurité.
  • ✓Lorsque vous voulez du code Go qui gère clairement les erreurs et évite les goroutines fuyantes.

Lien du skill

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

Copiez-le et collez-le dans votre IA (Claude, ChatGPT ou Cursor) en lui demandant de suivre les instructions.

Comment l’utiliser

Le plus simple : copiez le message et collez-le dans votre IA. Elle lit le skill et suit les instructions.

Message prêt à coller

Utilise ce skill pour m’aider : https://github.com/RightNow-AI/openfang/blob/main/crates/openfang-skills/bundled/golang-expert/SKILL.md Lis le fichier SKILL.md de ce lien et suis ses instructions pour ma tâche.
Envie que votre IA trouve seule des skills comme celui-ci ?Installez le MCP gratuit de Skillpedia : une ligne, et elle cherche parmi 15 000+ skills avant chaque tâche.Installer en 1 minute →

Exemple de demande à votre IA

“Écris un pool de workers Go qui traite une liste de tâches en parallèle et s'arrête proprement lorsque le contexte est annulé.”

5 nouveaux skills par semaine. 1 minute de lecture.

Comment ça marche

La skill applique les conventions Go, comme transmettre le contexte à travers les appels, des erreurs explicites, des chemins d'arrêt clairs et une conception de paquets simple.

Contenu technique (SKILL.md original)

Texte original de l’auteur, en anglais, directement depuis 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
Questions fréquentes

Qu'est-ce qu'une goroutine ?

C'est un thread léger géré par Go, utilisé pour exécuter des tâches en même temps.

Pourquoi la skill insiste-t-elle sur les chemins d'arrêt ?

Les goroutines qui ne s'arrêtent jamais sont fuyantes et peuvent consommer peu à peu la mémoire.

Qu'est-ce que le motif fan-out et fan-in ?

Il répartit le travail entre plusieurs workers, puis rassemble leurs résultats dans un seul consommateur.

Détails

Description originale de l’auteur

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

repo: RightNow-AI/openfang

Popularité

Étoiles GitHub
18k
Position au classement
#10681
Licence
Apache-2.0
Mis à jour
02/07/2026

Ce skill vous est-il utile ?

0

Connectez-vous pour voter.

Commentaires

  • …

Autres skills de ce dépôt

Skills similaires