[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6F1Y1AHFAJCT0VDDFRJTN2P":3,"skill-same:01M6F1Y1AHFAJCT0VDDFRJTN2P":126},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":28,"publishedAt":49,"linkOnly":50,"markdownContent":51,"markdownBody":52,"frontMatter":53,"refName":67,"commitSha":68,"skillDirectory":69,"forksCount":70,"repositoryHtmlUrl":71,"repositoryHomepageUrl":6,"ownerHtmlUrl":72,"ownerBlogUrl":6,"ownerDescription":73,"updatedAt":74,"install":75,"resources":87},"01M6F1Y1AHFAJCT0VDDFRJTN2P","golang-design-patterns",null,"Idiomatic 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.","luokai0\u002Fai-agent-skills-by-luo-kai","luokai0","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F266954973?v=4","01M6E16VNT42JB8B3X3254QWJ7","luo kai","01M6E16VTFVP6S5XJF1V1MPV90",14,"MIT","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns\u002FSKILL.md",[18,23],{"categoryNo":19,"categoryName":20,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000015","视觉设计","SCENARIO","使用场景",{"categoryNo":24,"categoryName":25,"taxonomyType":26,"taxonomyTypeDesc":27},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48],"golang","patterns","golang design patterns","design","design patterns","up","resilience patterns","functional","error","problem","options","shutdown","dependency","projects","Bash","streaming","code","resilience","ai coding agents","architecture","2026-11-10 10:12:30",false,"---\nname: golang-design-patterns\ndescription: \"Idiomatic 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.\"\nuser-invocable: true\nlicense: MIT\ncompatibility: Designed for Claude Code or similar AI coding agents, and for projects using Golang.\nmetadata:\n  author: samber\n  version: \"1.1.3\"\n  openclaw:\n    emoji: \"?️\"\n    homepage: https:\u002F\u002Fgithub.com\u002Fsamber\u002Fcc-skills-golang\n    requires:\n      bins:\n        - go\n    install: []\nallowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent AskUserQuestion\n---\n\n**Persona:** You are a Go architect who values simplicity and explicitness. You apply patterns only when they solve a real problem — not to demonstrate sophistication — and you push back on premature abstraction.\n\n**Modes:**\n\n- **Design mode** — creating new APIs, packages, or application structure: ask the developer about their architecture preference before proposing patterns; favor the smallest pattern that satisfies the requirement.\n- **Review mode** — auditing existing code for design issues: scan for `init()` abuse, unbounded resources, missing timeouts, and implicit global state; report findings before suggesting refactors.\n\n> **Community default.** A company skill that explicitly supersedes `samber\u002Fcc-skills-golang@golang-design-patterns` skill takes precedence.\n\n# Go Design Patterns & Idioms\n\nIdiomatic Go patterns for production-ready code. For error handling details see the `samber\u002Fcc-skills-golang@golang-error-handling` skill; for context propagation see `samber\u002Fcc-skills-golang@golang-context` skill; for struct\u002Finterface design see `samber\u002Fcc-skills-golang@golang-structs-interfaces` skill.\n\n## Best Practices Summary\n\n1. Constructors SHOULD use **functional options** — they scale better as APIs evolve (one function per option, no breaking changes)\n2. Functional options MUST **return an error** if validation can fail — catch bad config at construction, not at runtime\n3. **Avoid `init()`** — runs implicitly, cannot return errors, makes testing unpredictable. Use explicit constructors\n4. Enums SHOULD **start at 1** (or Unknown sentinel at 0) — Go's zero value silently passes as the first enum member\n5. Error cases MUST be **handled first** with early return — keep happy path flat\n6. **Panic is for bugs, not expected errors** — callers can handle returned errors; panics crash the process\n7. **`defer Close()` immediately after opening** — later code changes can accidentally skip cleanup\n8. **`runtime.AddCleanup`** over `runtime.SetFinalizer` — finalizers are unpredictable and can resurrect objects\n9. Every external call SHOULD **have a timeout** — a slow upstream hangs your goroutine indefinitely\n10. **Limit everything** (pool sizes, queue depths, buffers) — unbounded resources grow until they crash\n11. Retry logic MUST **check context cancellation** between attempts\n12. **Use `strings.Builder`** for concatenation in loops → see `samber\u002Fcc-skills-golang@golang-code-style`\n13. string vs []byte: **use `[]byte` for mutation and I\u002FO**, `string` for display and keys — conversions allocate\n14. Iterators (Go 1.23+): **use for lazy evaluation** — avoid loading everything into memory\n15. **Stream large transfers** — loading millions of rows causes OOM; stream keeps memory constant\n16. `\u002F\u002Fgo:embed` for **static assets** — embeds at compile time, eliminates runtime file I\u002FO errors\n17. **Use `crypto\u002Frand`** for keys\u002Ftokens — `math\u002Frand` is predictable → see `samber\u002Fcc-skills-golang@golang-security`\n18. Regexp MUST be **compiled once at package level** — compilation is O(n) and allocates\n19. Compile-time interface checks: **`var _ Interface = (*Type)(nil)`**\n20. **A little recode > a big dependency** — each dep adds attack surface and maintenance burden\n21. **Design for testability** — accept interfaces, inject dependencies\n\n## Constructor Patterns: Functional Options vs Builder\n\n### Functional Options (Preferred)\n\n```go\ntype Server struct {\n    addr         string\n    readTimeout  time.Duration\n    writeTimeout time.Duration\n    maxConns     int\n}\n\ntype Option func(*Server)\n\nfunc WithReadTimeout(d time.Duration) Option {\n    return func(s *Server) { s.readTimeout = d }\n}\n\nfunc WithWriteTimeout(d time.Duration) Option {\n    return func(s *Server) { s.writeTimeout = d }\n}\n\nfunc WithMaxConns(n int) Option {\n    return func(s *Server) { s.maxConns = n }\n}\n\nfunc NewServer(addr string, opts ...Option) *Server {\n    \u002F\u002F Default options\n    s := &Server{\n        addr:         addr,\n        readTimeout:  5 * time.Second,\n        writeTimeout: 10 * time.Second,\n        maxConns:     100,\n    }\n    for _, opt := range opts {\n        opt(s)\n    }\n    return s\n}\n\n\u002F\u002F Usage\nsrv := NewServer(\":8080\",\n    WithReadTimeout(30*time.Second),\n    WithMaxConns(500),\n)\n```\n\nConstructors SHOULD use **functional options** — they scale better with API evolution and require less code. Use builder pattern only if you need complex validation between configuration steps.\n\n## Constructors & Initialization\n\n### Avoid `init()` and Mutable Globals\n\n`init()` runs implicitly, makes testing harder, and creates hidden dependencies:\n\n- Multiple `init()` functions run in declaration order, across files in **filename alphabetical order** — fragile\n- Cannot return errors — failures must panic or `log.Fatal`\n- Runs before `main()` and tests — side effects make tests unpredictable\n\n```go\n\u002F\u002F Bad — hidden global state\nvar db *sql.DB\n\nfunc init() {\n    var err error\n    db, err = sql.Open(\"postgres\", os.Getenv(\"DATABASE_URL\"))\n    if err != nil {\n        log.Fatal(err)\n    }\n}\n\n\u002F\u002F Good — explicit initialization, injectable\nfunc NewUserRepository(db *sql.DB) *UserRepository {\n    return &UserRepository{db: db}\n}\n```\n\n### Enums: Start at 1\n\nZero values should represent invalid\u002Funset state:\n\n```go\ntype Status int\n\nconst (\n    StatusUnknown Status = iota \u002F\u002F 0 = invalid\u002Funset\n    StatusActive                \u002F\u002F 1\n    StatusInactive              \u002F\u002F 2\n    StatusSuspended             \u002F\u002F 3\n)\n```\n\n### Compile Regexp Once\n\n```go\n\u002F\u002F Good — compiled once at package level\nvar emailRegex = regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$`)\n\nfunc ValidateEmail(email string) bool {\n    return emailRegex.MatchString(email)\n}\n```\n\n### Use `\u002F\u002Fgo:embed` for Static Assets\n\n```go\nimport \"embed\"\n\n\u002F\u002Fgo:embed templates\u002F*\nvar templateFS embed.FS\n\n\u002F\u002Fgo:embed version.txt\nvar version string\n```\n\n### Compile-Time Interface Checks\n\n→ See `samber\u002Fcc-skills-golang@golang-structs-interfaces` for the `var _ Interface = (*Type)(nil)` pattern.\n\n## Error Flow Patterns\n\nError cases MUST be handled first with early return — keep the happy path at minimal indentation. → See `samber\u002Fcc-skills-golang@golang-code-style` for the full pattern and examples.\n\n### When to Panic vs Return Error\n\n- **Return error**: network failures, file not found, invalid input — anything a caller can handle\n- **Panic**: nil pointer in a place that should be impossible, violated invariant, `Must*` constructors used at init time\n- **`.Close()` errors**: acceptable to not check — `defer f.Close()` is fine without error handling\n\n## Data Handling\n\n### string vs []byte vs []rune\n\n| Type     | Default for | Use when                                            |\n| -------- | ----------- | --------------------------------------------------- |\n| `string` | Everything  | Immutable, safe, UTF-8                              |\n| `[]byte` | I\u002FO         | Writing to `io.Writer`, building strings, mutations |\n| `[]rune` | Unicode ops | `len()` must mean characters, not bytes             |\n\nAvoid repeated conversions — each one allocates. Stay in one type until you need the other.\n\n### Iterators & Streaming for Large Data\n\nUse iterators (Go 1.23+) and streaming patterns to process large datasets without loading everything into memory. For large transfers between services (e.g., 1M rows DB to HTTP), stream to prevent OOM.\n\nFor code examples, see [Data Handling Patterns](references\u002Fdata-handling.md).\n\n## Resource Management\n\n`defer Close()` immediately after opening — don't wait, don't forget:\n\n```go\nf, err := os.Open(path)\nif err != nil {\n    return err\n}\ndefer f.Close() \u002F\u002F right here, not 50 lines later\n\nrows, err := db.QueryContext(ctx, query)\nif err != nil {\n    return err\n}\ndefer rows.Close()\n```\n\nFor graceful shutdown, resource pools, and `runtime.AddCleanup`, see [Resource Management](references\u002Fresource-management.md).\n\n## Resilience & Limits\n\n### Timeout Every External Call\n\n```go\nctx, cancel := context.WithTimeout(ctx, 5*time.Second)\ndefer cancel()\n\nresp, err := httpClient.Do(req.WithContext(ctx))\n```\n\n### Retry & Context Checks\n\nRetry logic MUST check `ctx.Err()` between attempts and use exponential\u002Flinear backoff via `select` on `ctx.Done()`. Long loops MUST check `ctx.Err()` periodically. → See `samber\u002Fcc-skills-golang@golang-context` skill.\n\n## Database Patterns\n\n→ See `samber\u002Fcc-skills-golang@golang-database` skill for sqlx\u002Fpgx, transactions, nullable columns, connection pools, repository interfaces, testing.\n\n## Architecture\n\nAsk the developer which architecture they prefer: clean architecture, hexagonal, DDD, or flat layout. Don't impose complex architecture on a small project.\n\nCore principles regardless of architecture:\n\n- **Keep domain pure** — no framework dependencies in the domain layer\n- **Fail fast** — validate at boundaries, trust internal code\n- **Make illegal states unrepresentable** — use types to enforce invariants\n- **Respect 12-factor app** principles — → see `samber\u002Fcc-skills-golang@golang-project-layout`\n\n## Detailed Guides\n\n| Guide | Scope |\n| --- | --- |\n| [Architecture Patterns](references\u002Farchitecture.md) | High-level principles, when each architecture fits |\n| [Clean Architecture](references\u002Fclean-architecture.md) | Use cases, dependency rule, layered adapters |\n| [Hexagonal Architecture](references\u002Fhexagonal-architecture.md) | Ports and adapters, domain core isolation |\n| [Domain-Driven Design](references\u002Fddd.md) | Aggregates, value objects, bounded contexts |\n\n## Code Philosophy\n\n- **Avoid repetitive code** — but don't abstract prematurely\n- **Minimize dependencies** — a little recode > a big dependency\n- **Design for testability** — accept interfaces, inject dependencies, keep functions pure\n\n## Cross-References\n\n- → See `samber\u002Fcc-skills-golang@golang-data-structures` skill for data structure selection, internals, and container\u002F packages\n- → See `samber\u002Fcc-skills-golang@golang-error-handling` skill for error wrapping, sentinel errors, and the single handling rule\n- → See `samber\u002Fcc-skills-golang@golang-structs-interfaces` skill for interface design and composition\n- → See `samber\u002Fcc-skills-golang@golang-concurrency` skill for goroutine lifecycle and graceful shutdown\n- → See `samber\u002Fcc-skills-golang@golang-context` skill for timeout and cancellation patterns\n- → See `samber\u002Fcc-skills-golang@golang-project-layout` skill for architecture and directory structure\n","**Persona:** You are a Go architect who values simplicity and explicitness. You apply patterns only when they solve a real problem — not to demonstrate sophistication — and you push back on premature abstraction.\n\n**Modes:**\n\n- **Design mode** — creating new APIs, packages, or application structure: ask the developer about their architecture preference before proposing patterns; favor the smallest pattern that satisfies the requirement.\n- **Review mode** — auditing existing code for design issues: scan for `init()` abuse, unbounded resources, missing timeouts, and implicit global state; report findings before suggesting refactors.\n\n> **Community default.** A company skill that explicitly supersedes `samber\u002Fcc-skills-golang@golang-design-patterns` skill takes precedence.\n\n# Go Design Patterns & Idioms\n\nIdiomatic Go patterns for production-ready code. For error handling details see the `samber\u002Fcc-skills-golang@golang-error-handling` skill; for context propagation see `samber\u002Fcc-skills-golang@golang-context` skill; for struct\u002Finterface design see `samber\u002Fcc-skills-golang@golang-structs-interfaces` skill.\n\n## Best Practices Summary\n\n1. Constructors SHOULD use **functional options** — they scale better as APIs evolve (one function per option, no breaking changes)\n2. Functional options MUST **return an error** if validation can fail — catch bad config at construction, not at runtime\n3. **Avoid `init()`** — runs implicitly, cannot return errors, makes testing unpredictable. Use explicit constructors\n4. Enums SHOULD **start at 1** (or Unknown sentinel at 0) — Go's zero value silently passes as the first enum member\n5. Error cases MUST be **handled first** with early return — keep happy path flat\n6. **Panic is for bugs, not expected errors** — callers can handle returned errors; panics crash the process\n7. **`defer Close()` immediately after opening** — later code changes can accidentally skip cleanup\n8. **`runtime.AddCleanup`** over `runtime.SetFinalizer` — finalizers are unpredictable and can resurrect objects\n9. Every external call SHOULD **have a timeout** — a slow upstream hangs your goroutine indefinitely\n10. **Limit everything** (pool sizes, queue depths, buffers) — unbounded resources grow until they crash\n11. Retry logic MUST **check context cancellation** between attempts\n12. **Use `strings.Builder`** for concatenation in loops → see `samber\u002Fcc-skills-golang@golang-code-style`\n13. string vs []byte: **use `[]byte` for mutation and I\u002FO**, `string` for display and keys — conversions allocate\n14. Iterators (Go 1.23+): **use for lazy evaluation** — avoid loading everything into memory\n15. **Stream large transfers** — loading millions of rows causes OOM; stream keeps memory constant\n16. `\u002F\u002Fgo:embed` for **static assets** — embeds at compile time, eliminates runtime file I\u002FO errors\n17. **Use `crypto\u002Frand`** for keys\u002Ftokens — `math\u002Frand` is predictable → see `samber\u002Fcc-skills-golang@golang-security`\n18. Regexp MUST be **compiled once at package level** — compilation is O(n) and allocates\n19. Compile-time interface checks: **`var _ Interface = (*Type)(nil)`**\n20. **A little recode > a big dependency** — each dep adds attack surface and maintenance burden\n21. **Design for testability** — accept interfaces, inject dependencies\n\n## Constructor Patterns: Functional Options vs Builder\n\n### Functional Options (Preferred)\n\n```go\ntype Server struct {\n    addr         string\n    readTimeout  time.Duration\n    writeTimeout time.Duration\n    maxConns     int\n}\n\ntype Option func(*Server)\n\nfunc WithReadTimeout(d time.Duration) Option {\n    return func(s *Server) { s.readTimeout = d }\n}\n\nfunc WithWriteTimeout(d time.Duration) Option {\n    return func(s *Server) { s.writeTimeout = d }\n}\n\nfunc WithMaxConns(n int) Option {\n    return func(s *Server) { s.maxConns = n }\n}\n\nfunc NewServer(addr string, opts ...Option) *Server {\n    \u002F\u002F Default options\n    s := &Server{\n        addr:         addr,\n        readTimeout:  5 * time.Second,\n        writeTimeout: 10 * time.Second,\n        maxConns:     100,\n    }\n    for _, opt := range opts {\n        opt(s)\n    }\n    return s\n}\n\n\u002F\u002F Usage\nsrv := NewServer(\":8080\",\n    WithReadTimeout(30*time.Second),\n    WithMaxConns(500),\n)\n```\n\nConstructors SHOULD use **functional options** — they scale better with API evolution and require less code. Use builder pattern only if you need complex validation between configuration steps.\n\n## Constructors & Initialization\n\n### Avoid `init()` and Mutable Globals\n\n`init()` runs implicitly, makes testing harder, and creates hidden dependencies:\n\n- Multiple `init()` functions run in declaration order, across files in **filename alphabetical order** — fragile\n- Cannot return errors — failures must panic or `log.Fatal`\n- Runs before `main()` and tests — side effects make tests unpredictable\n\n```go\n\u002F\u002F Bad — hidden global state\nvar db *sql.DB\n\nfunc init() {\n    var err error\n    db, err = sql.Open(\"postgres\", os.Getenv(\"DATABASE_URL\"))\n    if err != nil {\n        log.Fatal(err)\n    }\n}\n\n\u002F\u002F Good — explicit initialization, injectable\nfunc NewUserRepository(db *sql.DB) *UserRepository {\n    return &UserRepository{db: db}\n}\n```\n\n### Enums: Start at 1\n\nZero values should represent invalid\u002Funset state:\n\n```go\ntype Status int\n\nconst (\n    StatusUnknown Status = iota \u002F\u002F 0 = invalid\u002Funset\n    StatusActive                \u002F\u002F 1\n    StatusInactive              \u002F\u002F 2\n    StatusSuspended             \u002F\u002F 3\n)\n```\n\n### Compile Regexp Once\n\n```go\n\u002F\u002F Good — compiled once at package level\nvar emailRegex = regexp.MustCompile(`^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$`)\n\nfunc ValidateEmail(email string) bool {\n    return emailRegex.MatchString(email)\n}\n```\n\n### Use `\u002F\u002Fgo:embed` for Static Assets\n\n```go\nimport \"embed\"\n\n\u002F\u002Fgo:embed templates\u002F*\nvar templateFS embed.FS\n\n\u002F\u002Fgo:embed version.txt\nvar version string\n```\n\n### Compile-Time Interface Checks\n\n→ See `samber\u002Fcc-skills-golang@golang-structs-interfaces` for the `var _ Interface = (*Type)(nil)` pattern.\n\n## Error Flow Patterns\n\nError cases MUST be handled first with early return — keep the happy path at minimal indentation. → See `samber\u002Fcc-skills-golang@golang-code-style` for the full pattern and examples.\n\n### When to Panic vs Return Error\n\n- **Return error**: network failures, file not found, invalid input — anything a caller can handle\n- **Panic**: nil pointer in a place that should be impossible, violated invariant, `Must*` constructors used at init time\n- **`.Close()` errors**: acceptable to not check — `defer f.Close()` is fine without error handling\n\n## Data Handling\n\n### string vs []byte vs []rune\n\n| Type     | Default for | Use when                                            |\n| -------- | ----------- | --------------------------------------------------- |\n| `string` | Everything  | Immutable, safe, UTF-8                              |\n| `[]byte` | I\u002FO         | Writing to `io.Writer`, building strings, mutations |\n| `[]rune` | Unicode ops | `len()` must mean characters, not bytes             |\n\nAvoid repeated conversions — each one allocates. Stay in one type until you need the other.\n\n### Iterators & Streaming for Large Data\n\nUse iterators (Go 1.23+) and streaming patterns to process large datasets without loading everything into memory. For large transfers between services (e.g., 1M rows DB to HTTP), stream to prevent OOM.\n\nFor code examples, see [Data Handling Patterns](references\u002Fdata-handling.md).\n\n## Resource Management\n\n`defer Close()` immediately after opening — don't wait, don't forget:\n\n```go\nf, err := os.Open(path)\nif err != nil {\n    return err\n}\ndefer f.Close() \u002F\u002F right here, not 50 lines later\n\nrows, err := db.QueryContext(ctx, query)\nif err != nil {\n    return err\n}\ndefer rows.Close()\n```\n\nFor graceful shutdown, resource pools, and `runtime.AddCleanup`, see [Resource Management](references\u002Fresource-management.md).\n\n## Resilience & Limits\n\n### Timeout Every External Call\n\n```go\nctx, cancel := context.WithTimeout(ctx, 5*time.Second)\ndefer cancel()\n\nresp, err := httpClient.Do(req.WithContext(ctx))\n```\n\n### Retry & Context Checks\n\nRetry logic MUST check `ctx.Err()` between attempts and use exponential\u002Flinear backoff via `select` on `ctx.Done()`. Long loops MUST check `ctx.Err()` periodically. → See `samber\u002Fcc-skills-golang@golang-context` skill.\n\n## Database Patterns\n\n→ See `samber\u002Fcc-skills-golang@golang-database` skill for sqlx\u002Fpgx, transactions, nullable columns, connection pools, repository interfaces, testing.\n\n## Architecture\n\nAsk the developer which architecture they prefer: clean architecture, hexagonal, DDD, or flat layout. Don't impose complex architecture on a small project.\n\nCore principles regardless of architecture:\n\n- **Keep domain pure** — no framework dependencies in the domain layer\n- **Fail fast** — validate at boundaries, trust internal code\n- **Make illegal states unrepresentable** — use types to enforce invariants\n- **Respect 12-factor app** principles — → see `samber\u002Fcc-skills-golang@golang-project-layout`\n\n## Detailed Guides\n\n| Guide | Scope |\n| --- | --- |\n| [Architecture Patterns](references\u002Farchitecture.md) | High-level principles, when each architecture fits |\n| [Clean Architecture](references\u002Fclean-architecture.md) | Use cases, dependency rule, layered adapters |\n| [Hexagonal Architecture](references\u002Fhexagonal-architecture.md) | Ports and adapters, domain core isolation |\n| [Domain-Driven Design](references\u002Fddd.md) | Aggregates, value objects, bounded contexts |\n\n## Code Philosophy\n\n- **Avoid repetitive code** — but don't abstract prematurely\n- **Minimize dependencies** — a little recode > a big dependency\n- **Design for testability** — accept interfaces, inject dependencies, keep functions pure\n\n## Cross-References\n\n- → See `samber\u002Fcc-skills-golang@golang-data-structures` skill for data structure selection, internals, and container\u002F packages\n- → See `samber\u002Fcc-skills-golang@golang-error-handling` skill for error wrapping, sentinel errors, and the single handling rule\n- → See `samber\u002Fcc-skills-golang@golang-structs-interfaces` skill for interface design and composition\n- → See `samber\u002Fcc-skills-golang@golang-concurrency` skill for goroutine lifecycle and graceful shutdown\n- → See `samber\u002Fcc-skills-golang@golang-context` skill for timeout and cancellation patterns\n- → See `samber\u002Fcc-skills-golang@golang-project-layout` skill for architecture and directory structure\n",{"name":5,"license":15,"metadata":54,"description":7,"allowed-tools":64,"compatibility":65,"user-invocable":66},{"author":55,"version":56,"openclaw":57},"samber","1.1.3",{"emoji":58,"install":59,"homepage":60,"requires":61},"?️",[],"https:\u002F\u002Fgithub.com\u002Fsamber\u002Fcc-skills-golang",{"bins":62},[63],"go","Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent AskUserQuestion","Designed for Claude Code or similar AI coding agents, and for projects using Golang.",true,"main","4d2fb89cdfb75f3f6fd3c6c5ec9ad90ea129eb3c","ai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns",1,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai","https:\u002F\u002Fgithub.com\u002Fluokai0","a solo builder.","2026-05-06 04:29:04",{"source":8,"skillName":5,"commands":76,"prompt":86,"zipAvailable":66},[77,80,83],{"tool":78,"command":79},"npx","npx skills add luokai0\u002Fai-agent-skills-by-luo-kai --skill golang-design-patterns",{"tool":81,"command":82},"bunx","bunx skills add luokai0\u002Fai-agent-skills-by-luo-kai --skill golang-design-patterns",{"tool":84,"command":85},"pnpm","pnpm dlx skills add luokai0\u002Fai-agent-skills-by-luo-kai --skill golang-design-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns\u002FSKILL.md",[88,94,98,102,106,110,114,118,122],{"path":89,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":92,"sourceHtmlUrl":93},"_meta.json","REFERENCE","参考文档",141,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns\u002F_meta.json",{"path":95,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":96,"sourceHtmlUrl":97},".clawhub\u002Forigin.json",154,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns\u002F.clawhub\u002Forigin.json",{"path":99,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":100,"sourceHtmlUrl":101},"evals\u002Fevals.json",20756,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns\u002Fevals\u002Fevals.json",{"path":103,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":104,"sourceHtmlUrl":105},"references\u002Farchitecture.md",4786,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns\u002Freferences\u002Farchitecture.md",{"path":107,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":108,"sourceHtmlUrl":109},"references\u002Fclean-architecture.md",5127,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns\u002Freferences\u002Fclean-architecture.md",{"path":111,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":112,"sourceHtmlUrl":113},"references\u002Fdata-handling.md",1667,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns\u002Freferences\u002Fdata-handling.md",{"path":115,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":116,"sourceHtmlUrl":117},"references\u002Fddd.md",6916,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns\u002Freferences\u002Fddd.md",{"path":119,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":120,"sourceHtmlUrl":121},"references\u002Fhexagonal-architecture.md",6180,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns\u002Freferences\u002Fhexagonal-architecture.md",{"path":123,"resourceType":90,"resourceTypeDesc":91,"sizeBytes":124,"sourceHtmlUrl":125},"references\u002Fresource-management.md",4119,"https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fgolang-design-patterns\u002Freferences\u002Fresource-management.md",[127,154,171,197,230,265],{"skillNo":128,"name":129,"nameZh":6,"description":130,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":131,"categories":132,"keywords":133,"publishedAt":49},"01M6F2SKTE208174C7S7JJCZC7","write-contracts","Generates secure Aptos Move V2 smart contracts with Object model, Digital Asset integration, security patterns, and storage type guidance. Includes comprehensive storage decision framework for optimal data structure selection. Triggers on: 'write contract', 'create NFT collection', 'build marketplace', 'implement minting', 'generate Move module', 'create token contract', 'build DAO', 'implement staking'. Ask storage questions when: 'store', 'track', 'registry', 'mapping', 'list', 'collection'.","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fwrite-contracts\u002FSKILL.md",[],[134,135,136,137,138,139,140,141,142,143,144,145,146,147,148,149,150,151,152,153],"write","contracts","write contracts","storage","secure","create","generate","collection","model","decision","ask","smart-contracts","selection","objects","structure","nft","token","aptos","critical","move",{"skillNo":155,"name":156,"nameZh":6,"description":157,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":158,"categories":159,"keywords":160,"publishedAt":49},"01M6F2RFXJ6T9MKW0A7N7GM45B","web-search","通用网络搜索技能，支持多引擎搜索（百度、必应、DuckDuckGo），无需API密钥即可获取实时信息","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fweb-search-ex-skill\u002FSKILL.md",[],[161,162,163,164,165,166,167,168,169,170],"web","search","web search","搜索","baidu","bing","duckduckgo","百度","多引擎","internet",{"skillNo":172,"name":173,"nameZh":6,"description":174,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":175,"categories":176,"keywords":180,"publishedAt":49},"01M6F2K968G1FZEZFPW2E6B222","solo-build","Execute implementation plan tasks with TDD workflow, auto-commit, and phase gates. Use when user says \"build it\", \"start building\", \"execute plan\", \"implement tasks\", \"ship it\", or references a track ID. Do NOT use for planning (use \u002Fplan) or scaffolding (use \u002Fscaffold).","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fsolo-build\u002FSKILL.md",[177],{"categoryNo":178,"categoryName":179,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000023","Skill与智能体开发",[181,182,183,184,185,186,187,45,162,43,188,189,134,190,191,192,193,194,195,196],"build","solo","solo build","MCP","workflow","commit","tasks","plan","read","auto","references","context7","query","scaffolding","ship it","project",{"skillNo":198,"name":199,"nameZh":6,"description":200,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":201,"categories":202,"keywords":209,"publishedAt":49},"01M6F2GKN39SGHSPWYB3662YC8","react-email","Use when building HTML email templates with React components, adding a visual email editor to an application using the React Email visual editor, rendering emails to HTML, or sending emails with Resend. Covers welcome emails, password resets, notifications, order confirmations, newsletters, transactional emails, and the embeddable email editor component.","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Freact-email-skills\u002FSKILL.md",[203,206],{"categoryNo":204,"categoryName":205,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000005","邮件与沟通",{"categoryNo":207,"categoryName":208,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000009","前端开发",[210,211,212,213,214,215,216,217,218,219,220,221,222,223,224,225,226,227,228,229],"react","email","react email","github","editor","components","react components","component","welcome","https","notifications","password","node","use","html","resend","visual","emails","rendering","with",{"skillNo":231,"name":232,"nameZh":6,"description":233,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":234,"categories":235,"keywords":246,"publishedAt":49},"01M6F2FBVGVDFSG8SSFJGXA40C","APITester Agent-Driven API Testing","Test API endpoints and document responses. Define tests in plain English, run them, get formatted results. Agent-driven Postman alternative.","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fopenclaw-api-tester\u002FSKILL.md",[236,239,242,243],{"categoryNo":237,"categoryName":238,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000008","测试与质量",{"categoryNo":240,"categoryName":241,"taxonomyType":21,"taxonomyTypeDesc":22},"01JBSEEDCAT000000000000010","后端与接口",{"categoryNo":178,"categoryName":179,"taxonomyType":21,"taxonomyTypeDesc":22},{"categoryNo":244,"categoryName":245,"taxonomyType":26,"taxonomyTypeDesc":27},"01JBSEEDCAT000000000000030","开发工程师",[247,248,249,250,251,252,253,254,255,256,257,258,259,260,261,262,263,264],"testing","api","api testing","driven","APITester Agent Driven API Testing","test","run","postman","results","plain english","tester","endpoints","document","get","define","tests","english","api-tester",{"skillNo":266,"name":267,"nameZh":6,"description":268,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":269,"categories":270,"keywords":271,"publishedAt":49},"01M6F273Y3NGAPVJZ608BC0G9G","hubspot-implementation-plan","Generate a phased implementation plan from a HubSpot audit report. Creates prioritized, sequenced cleanup processes with effort estimates, dependencies, and automation feasibility. Use after running \u002Fhubspot-audit.","https:\u002F\u002Fgithub.com\u002Fluokai0\u002Fai-agent-skills-by-luo-kai\u002Fblob\u002Fmain\u002Fai-agent-skills\u002F22-clawhub-skills\u002Fhubspot-implementation-plan\u002FSKILL.md",[],[188,272,273,274,275,276,277,140,278,279,280,281,282,223,283,284,229,285],"implementation","hubspot","hubspot implementation plan","automation","feasibility","cleanup","planning","report","audit","audit report","phased implementation","dependencies","processes","hubspot audit"]