Solizardking/clawd-bot / .agents/skills/golang-design-patterns
golang-design-patterns
VerifiedIdiomatic Golang design patterns — functional options, constructors, error flow and cascading, resource management and lifecycle, graceful shutdown, resilience, architecture, dependency injection, data handling, streaming, and more. Apply when explicitly choosing between architectural patterns, implementing functional options, designing constructor APIs, setting up graceful shutdown, applying resilience patterns, or asking which idiomatic Go pattern fits a specific problem.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 11.4 KB |
| evals/evals.json | config | 20.3 KB |
| references/architecture.md | markdown | 4.7 KB |
| references/clean-architecture.md | markdown | 5.0 KB |
| references/data-handling.md | markdown | 1.6 KB |
| references/ddd.md | markdown | 6.8 KB |
| references/hexagonal-architecture.md | markdown | 6.0 KB |
| references/resource-management.md | markdown | 4.0 KB |
references/data-handling.md
View on GitHub# Data Handling Patterns
## Iterators for Large Data (Go 1.23+)
Process large datasets without allocating everything into memory:
```go
// Bad — loads all rows into memory
func AllUsers(db *sql.DB) ([]User, error) {
rows, err := db.Query("SELECT * FROM users")
// ... scan all into slice
}
// Good — iterator yields one at a time
func AllUsers(db *sql.DB) iter.Seq2[User, error] {
return func(yield func(User, error) bool) {
rows, err := db.Query("SELECT * FROM users")
if err != nil {
yield(User{}, err)
return
}
defer rows.Close()
for rows.Next() {
var u User
if err := rows.Scan(&u.ID, &u.Name, &u.Email); err != nil {
yield(User{}, err)
return
}
if !yield(u, nil) {
return
}
}
}
}
```
## Streaming Large Transfers
When transferring large data between services (e.g., 1M rows from DB, 1M rows in HTTP response), use streaming patterns with iterators or `github.com/samber/ro` to prevent OOM:
```go
// Stream JSON array to HTTP response — constant memory
func (h *Handler) ExportUsers(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.Write([]byte("["))
first := true
for user, err := range h.repo.AllUsers(r.Context()) {
if err != nil {
slog.Error("streaming user", "error", err)
return
}
if !first {
w.Write([]byte(","))
}
json.NewEncoder(w).Encode(user)
first = false
}
w.Write([]byte("]"))
}
```
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |