go-project-layout
Über
Diese Fähigkeit erstellt Gerüste für neue Go-Projekte mit geeigneten Verzeichnisstrukturen und Konventionen, basierend auf der Projektgröße. Sie hilft Entwicklern bei der Wahl zwischen flachen Layouts oder strukturierten Ansätzen mit cmd/- und internal/-Verzeichnissen und behandelt Modulbenennung sowie die Verdrahtung des Hauptpakets. Verwenden Sie sie beim Start eines neuen Go-Moduls oder -Dienstes, jedoch nicht zur Überprüfung bestehender Architekturen oder für detaillierte Dependency Injection.
Schnellinstallation
Claude Code
Empfohlennpx skills add eduardo-sl/go-agent-skills -a claude-code/plugin add https://github.com/eduardo-sl/go-agent-skillsgit clone https://github.com/eduardo-sl/go-agent-skills.git ~/.claude/skills/go-project-layoutKopieren Sie diesen Befehl und fügen Sie ihn in Claude Code ein, um diese Fähigkeit zu installieren
Dokumentation
Go Project Layout
Structure follows size. The biggest layout mistake in Go is copying a microservice skeleton for a 500-line tool — or growing a 50-package service inside a flat directory. Match the layout to the project.
1. Pick the Layout by Project Size
| Project | Layout |
|---|---|
| Small tool, single binary, <5 files | Flat: everything in package main at the root |
| Library for others to import | Root package named after the module, internal/ for helpers |
| Service with one binary | cmd/<name>/main.go + internal/ packages |
| Multiple binaries sharing code | cmd/<name1>/, cmd/<name2>/ + internal/ |
Never start with empty pkg/, api/, docs/, build/ directories
"for later". Add structure when the code demands it, not before.
2. Module Naming
# ✅ Good — repository path, lowercase
go mod init github.com/acme/payment-service
# ❌ Bad — not fetchable, uppercase, or vanity without DNS
go mod init PaymentService
go mod init payment_service
The last path element should match what users will see: for a library, it becomes the default import name.
3. Service Layout (the default for APIs and workers)
payment-service/
├── cmd/
│ └── payment-api/
│ └── main.go # flag/env parsing, wiring, Run() — nothing else
├── internal/
│ ├── domain/ # core types, business rules; zero external deps
│ ├── service/ # use cases orchestrating domain + stores
│ ├── store/ # data access implementations (postgres/, redis/)
│ ├── handler/ # HTTP/gRPC adapters
│ └── config/ # config loading and validation
├── migrations/ # if the service owns a database
├── go.mod
├── Makefile
└── README.md
Rules:
internal/by default — the compiler enforces that nobody outside the module imports it. Promote to a public package only on demand.pkg/only when external consumers exist AND the module also has private code. When in doubt, don't create it.- Dependencies point inward:
handler → service → domain ← store.domainimports neitherstorenorhandler.
4. Thin main, Runnable Run
Keep main.go to wiring plus a delegating call, so the app is testable:
func main() {
if err := run(context.Background(), os.Args[1:], os.Getenv); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run(ctx context.Context, args []string, getenv func(string) string) error {
cfg, err := config.Load(getenv)
if err != nil {
return fmt.Errorf("load config: %w", err)
}
db, err := store.Open(ctx, cfg.DatabaseURL)
if err != nil {
return fmt.Errorf("open db: %w", err)
}
defer db.Close()
svc := service.New(store.NewUserRepo(db))
srv := handler.NewServer(cfg.Addr, svc)
return srv.ListenAndServe(ctx)
}
os.Exitappears exactly once, inmain.runtakes its dependencies (args,getenv) so tests can call it.- No
init()functions for wiring — explicit construction order only.
5. Library Layout
retry/
├── retry.go # package retry — the API, in the root
├── retry_test.go
├── backoff.go # same package, split by topic
├── internal/
│ └── clock/ # implementation details users must not import
├── examples_test.go # Example* functions shown in godoc
└── go.mod
- The root directory IS the package. No
src/, nolib/. - One package per concept. Resist
util,common,helpers— name packages after what they provide (retry,clock,httpsign).
6. Naming Rules for Directories and Packages
- Package name == directory name, short, lowercase, no underscores:
store/postgres, notstore/postgres_impl. - Don't stutter:
payment.Service, notpayment.PaymentService. - Binary names in
cmd/are user-facing:cmd/payment-api, hyphenated is fine (directory only holds packagemain).
7. Files That Belong at the Root
go.mod,go.sum,README.md,LICENSE,Makefile,.golangci.yml,Dockerfile(single-binary projects).- Do NOT create:
src/(un-idiomatic),vendor/(unless the team explicitly vendors), one-file packages liketypes/ormodels/that become dumping grounds.
Scaffolding Procedure
- Ask/decide: tool, library, or service? How many binaries?
go mod init <repo-path>.- Create only the directories the first feature needs.
- Write
main.gowith the thin-main pattern above. - Add
Makefiletargets:build,test,lint. - Verify:
go build ./...andgo vet ./...pass on the skeleton.
Verification Checklist
- Layout matches project size — no empty scaffolding directories
- Module path is the fetchable repository path
- All non-public packages live under
internal/ main.gois thin: parse, wire, callrun, exitos.Exitonly inmain; no wiring ininit()- Dependencies flow inward;
domainhas zero infrastructure imports - No
util/common/helpers/modelsgrab-bag packages - Package names match directories, lowercase, no stutter
go build ./...passes on the fresh skeleton
GitHub Repository
Häufig gestellte Fragen
Was ist der Skill go-project-layout?
go-project-layout ist ein Claude Skill von eduardo-sl. Skills bündeln Anweisungen und Ressourcen, die Claude bei Bedarf lädt, um Aufgaben rund um go-project-layout ohne zusätzliche Eingaben auszuführen.
Wie installiere ich go-project-layout?
Verwende die Installationsbefehle auf dieser Seite: Füge go-project-layout 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-project-layout?
go-project-layout gehört zur Kategorie Meta.
Kann ich go-project-layout kostenlos nutzen?
Ja. go-project-layout ist auf AIMCP gelistet und kann kostenlos installiert werden.
Verwandte Skills
Diese Skill bietet eine produktionsgetestete Einrichtung für Content Collections – ein TypeScript-first-Tool, das Markdown/MDX-Dateien in typsichere Datensammlungen mit Zod-Validierung umwandelt. Verwenden Sie ihn beim Erstellen von Blogs, Dokumentationsseiten oder inhaltsstarken Vite + React-Anwendungen, um Typsicherheit und automatische Inhaltsvalidierung zu gewährleisten. Er behandelt alles von der Vite-Plugin-Konfiguration und MDX-Kompilierung bis hin zur Deployment-Optimierung und Schema-Validierung.
Diese Fähigkeit ermöglicht es Entwicklern, Anwendungen mit der Polymarket-Prognosemärkte-Plattform zu erstellen, einschließlich API-Integration für Handel und Marktdaten. Sie bietet außerdem Echtzeit-Datenstreaming über WebSocket, um Live-Trades und Marktaktivitäten zu überwachen. Nutzen Sie sie zur Implementierung von Handelsstrategien oder zur Erstellung von Tools, die Live-Marktaktualisierungen verarbeiten.
Diese Fähigkeit unterstützt Entwickler dabei, OpenCode-Plugins zu erstellen, die in über 25 Ereignistypen wie Befehle, Dateien und LSP-Operationen eingreifen. Sie bietet die Plugin-Struktur, Event-API-Spezifikationen und Implementierungsmuster für JavaScript/TypeScript-Module. Nutzen Sie sie, wenn Sie den Lebenszyklus des OpenCode KI-Assistenten mit benutzerdefinierter ereignisgesteuerter Logik abfangen, überwachen oder erweitern müssen.
SGLang ist ein hochperformantes LLM-Serving-Framework, das sich auf schnelle, strukturierte Generierung für JSON, Regex und agentenbasierte Workflows unter Verwendung seines RadixAttention-Prefix-Cachings spezialisiert. Es bietet deutlich schnellere Inferenz, insbesondere für Aufgaben mit wiederholten Präfixen, was es ideal für komplexe, strukturierte Ausgaben und Mehrfachdialoge macht. Wählen Sie SGLang gegenüber Alternativen wie vLLM, wenn Sie constrained decoding benötigen oder Anwendungen mit umfangreicher Präfix-Weitergabe entwickeln.
