[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M79Z6E0HFSFY08V1RC64518F":3,"skill-same:01M79Z6E0HFSFY08V1RC64518F":52},{"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":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":31,"commitSha":32,"skillDirectory":33,"forksCount":14,"repositoryHtmlUrl":34,"repositoryHomepageUrl":6,"ownerHtmlUrl":35,"ownerBlogUrl":36,"ownerDescription":37,"updatedAt":38,"install":39,"resources":51},"01M79Z6E0HFSFY08V1RC64518F","go-dependency-injection",null,"Dependency injection in Go: constructor injection, wiring in main, avoiding global state, and when frameworks (wire, fx, dig) earn their complexity. Use when: \"dependency injection\", \"wire up dependencies\", \"inject this\", \"remove global state\", \"singleton in Go\", \"use google\u002Fwire\", \"uber fx\", \"make this testable\". Not for: interface design (go-interface-design), directory structure (go-project-layout), test doubles and mocks (go-test-quality).","kongnakornna\u002Fgolangapi","kongnakornna","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F10528904?v=4","01M79Z5JQPPV5CWQHXS235Q9MD","Kongnakorn Jantakun","01M79Z5JRHJJJ6PR2DGQS4P985",0,"MIT","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Fgo-agent-skills\u002Fskills\u002F(architecture)\u002Fgo-dependency-injection\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: go-dependency-injection\ndescription: >\n  Dependency injection in Go: constructor injection, wiring in main,\n  avoiding global state, and when frameworks (wire, fx, dig) earn their\n  complexity. Use when: \"dependency injection\", \"wire up dependencies\",\n  \"inject this\", \"remove global state\", \"singleton in Go\", \"use\n  google\u002Fwire\", \"uber fx\", \"make this testable\".\n  Not for: interface design (go-interface-design), directory structure\n  (go-project-layout), test doubles and mocks (go-test-quality).\nuser-invocable: true\nlicense: MIT\ncompatibility: Designed for Claude Code or similar AI coding agents working on Go projects. Requires the Go toolchain. wire and fx are optional.\nallowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(gofmt:*)\nmetadata:\n  author: eduardo-sl\n  version: \"1.1.1\"\n---\n\n# Go Dependency Injection\n\nDI in Go is a pattern, not a framework: pass dependencies to\nconstructors, wire everything explicitly in `main`. Reach for a\nframework only when manual wiring measurably hurts.\n\n## 1. Constructor Injection — the Default\n\n```go\n\u002F\u002F ✅ Good — dependencies are explicit parameters\ntype OrderService struct {\n    repo     OrderRepository\n    payments PaymentGateway\n    logger   *slog.Logger\n}\n\nfunc NewOrderService(repo OrderRepository, payments PaymentGateway, logger *slog.Logger) *OrderService {\n    return &OrderService{repo: repo, payments: payments, logger: logger}\n}\n\n\u002F\u002F ❌ Bad — hidden dependencies reached through globals\nfunc (s *OrderService) Place(ctx context.Context, o Order) error {\n    db := database.Get()        \u002F\u002F global singleton\n    log.Printf(\"placing order\") \u002F\u002F global logger\n    \u002F\u002F untestable without touching process-wide state\n}\n```\n\nRules:\n\n- Accept interfaces for dependencies the service calls; return the\n  concrete type from the constructor.\n- Every dependency visible in the signature — if the list feels long,\n  the type does too much (split it), don't hide deps to shorten it.\n- Validate required deps in the constructor and return an error\n  (or accept a nil-safe default, e.g. `logger = slog.Default()`).\n\n## 2. The Composition Root\n\nAll wiring lives in one place — `main` (or a `run` function it calls).\nConstruction order is the dependency order, checked by the compiler:\n\n```go\nfunc run(ctx context.Context, cfg Config) error {\n    db, err := store.Open(ctx, cfg.DatabaseURL)\n    if err != nil {\n        return fmt.Errorf(\"open db: %w\", err)\n    }\n    defer db.Close()\n\n    orderRepo := store.NewOrderRepo(db)\n    payments := stripe.NewGateway(cfg.StripeKey)\n    logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))\n\n    orders := service.NewOrderService(orderRepo, payments, logger)\n    server := handler.NewServer(cfg.Addr, orders)\n\n    return server.ListenAndServe(ctx)\n}\n```\n\n- No package builds its own dependencies; it receives them.\n- No `init()` wiring, no package-level `var DB *sql.DB`.\n- Two binaries needing different wiring = two mains, same components.\n\n## 3. Eliminating Global State\n\n```go\n\u002F\u002F ❌ Before — package-level singleton\nvar defaultClient *api.Client\n\nfunc Fetch(id string) (*Item, error) {\n    return defaultClient.Get(id)\n}\n\n\u002F\u002F ✅ After — the dependency moves into a struct\ntype Fetcher struct {\n    client *api.Client\n}\n\nfunc NewFetcher(c *api.Client) *Fetcher { return &Fetcher{client: c} }\n\nfunc (f *Fetcher) Fetch(id string) (*Item, error) {\n    return f.client.Get(id)\n}\n```\n\nMigration path for a legacy codebase: introduce the struct, keep a\ndeprecated package-level wrapper delegating to one instance built in\n`main`, move callers over, delete the wrapper.\n\nAcceptable package-level state: pure constants, compiled regexps,\n`sync.Once`-guarded process singletons that hold no config.\n\n## 4. Function Dependencies for Small Seams\n\nA full interface is overkill for one function — inject the function:\n\n```go\ntype Service struct {\n    now     func() time.Time\n    genID   func() string\n    publish func(ctx context.Context, e Event) error\n}\n\n\u002F\u002F Production: Service{now: time.Now, genID: uuid.NewString, publish: bus.Publish}\n\u002F\u002F Test:       Service{now: fixedTime, genID: constID, publish: capture}\n```\n\n## 5. When Frameworks Earn Their Complexity\n\nManual wiring scales further than expected — a 100-line `run` function\nis still readable and compiler-checked. Consider a tool when wiring\ncrosses hundreds of components or many teams share one binary.\n\n| Tool | Model | Trade-off |\n|---|---|---|\n| google\u002Fwire | Compile-time code generation | Wiring stays plain Go and compiler-checked; adds a codegen step |\n| uber-go\u002Ffx | Runtime container + lifecycle | App lifecycle (start\u002Fstop hooks) managed; errors surface at runtime, magic in stack traces |\n| uber-go\u002Fdig | Runtime container (fx's core) | Same runtime trade-offs, no lifecycle layer |\n\nDecision rule: prefer manual wiring; if generation becomes necessary\nprefer wire (failures at compile time beat failures at startup); adopt\nfx only when you also want its lifecycle management and your team\naccepts the runtime container.\n\nNever mix models: one composition root, one mechanism.\n\n## 6. Wire Example (when chosen)\n\n```go\n\u002F\u002Fgo:build wireinject\n\nfunc InitializeServer(cfg Config) (*handler.Server, error) {\n    wire.Build(\n        store.Open,\n        store.NewOrderRepo,\n        stripe.NewGateway,\n        service.NewOrderService,\n        handler.NewServer,\n    )\n    return nil, nil \u002F\u002F replaced by generated code\n}\n```\n\n`wire` generates the ordered constructor calls; the generated file is\ncommitted and reviewed like handwritten code.\n\n## Verification Checklist\n\n1. Every service\u002Fhandler receives dependencies via constructor parameters\n2. No package-level mutable singletons (`var DB`, `var logger`, `Get()` accessors)\n3. All wiring concentrated in main\u002Frun — no `init()` construction\n4. Dependencies accepted as interfaces (or funcs), concrete types returned\n5. Constructors validate required dependencies\n6. Components testable by passing fakes — no process-global setup in tests\n7. If a DI tool is used: exactly one, at the composition root only\n8. `go build .\u002F...` passes — wiring errors surface at compile time\n","# Go Dependency Injection\n\nDI in Go is a pattern, not a framework: pass dependencies to\nconstructors, wire everything explicitly in `main`. Reach for a\nframework only when manual wiring measurably hurts.\n\n## 1. Constructor Injection — the Default\n\n```go\n\u002F\u002F ✅ Good — dependencies are explicit parameters\ntype OrderService struct {\n    repo     OrderRepository\n    payments PaymentGateway\n    logger   *slog.Logger\n}\n\nfunc NewOrderService(repo OrderRepository, payments PaymentGateway, logger *slog.Logger) *OrderService {\n    return &OrderService{repo: repo, payments: payments, logger: logger}\n}\n\n\u002F\u002F ❌ Bad — hidden dependencies reached through globals\nfunc (s *OrderService) Place(ctx context.Context, o Order) error {\n    db := database.Get()        \u002F\u002F global singleton\n    log.Printf(\"placing order\") \u002F\u002F global logger\n    \u002F\u002F untestable without touching process-wide state\n}\n```\n\nRules:\n\n- Accept interfaces for dependencies the service calls; return the\n  concrete type from the constructor.\n- Every dependency visible in the signature — if the list feels long,\n  the type does too much (split it), don't hide deps to shorten it.\n- Validate required deps in the constructor and return an error\n  (or accept a nil-safe default, e.g. `logger = slog.Default()`).\n\n## 2. The Composition Root\n\nAll wiring lives in one place — `main` (or a `run` function it calls).\nConstruction order is the dependency order, checked by the compiler:\n\n```go\nfunc run(ctx context.Context, cfg Config) error {\n    db, err := store.Open(ctx, cfg.DatabaseURL)\n    if err != nil {\n        return fmt.Errorf(\"open db: %w\", err)\n    }\n    defer db.Close()\n\n    orderRepo := store.NewOrderRepo(db)\n    payments := stripe.NewGateway(cfg.StripeKey)\n    logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))\n\n    orders := service.NewOrderService(orderRepo, payments, logger)\n    server := handler.NewServer(cfg.Addr, orders)\n\n    return server.ListenAndServe(ctx)\n}\n```\n\n- No package builds its own dependencies; it receives them.\n- No `init()` wiring, no package-level `var DB *sql.DB`.\n- Two binaries needing different wiring = two mains, same components.\n\n## 3. Eliminating Global State\n\n```go\n\u002F\u002F ❌ Before — package-level singleton\nvar defaultClient *api.Client\n\nfunc Fetch(id string) (*Item, error) {\n    return defaultClient.Get(id)\n}\n\n\u002F\u002F ✅ After — the dependency moves into a struct\ntype Fetcher struct {\n    client *api.Client\n}\n\nfunc NewFetcher(c *api.Client) *Fetcher { return &Fetcher{client: c} }\n\nfunc (f *Fetcher) Fetch(id string) (*Item, error) {\n    return f.client.Get(id)\n}\n```\n\nMigration path for a legacy codebase: introduce the struct, keep a\ndeprecated package-level wrapper delegating to one instance built in\n`main`, move callers over, delete the wrapper.\n\nAcceptable package-level state: pure constants, compiled regexps,\n`sync.Once`-guarded process singletons that hold no config.\n\n## 4. Function Dependencies for Small Seams\n\nA full interface is overkill for one function — inject the function:\n\n```go\ntype Service struct {\n    now     func() time.Time\n    genID   func() string\n    publish func(ctx context.Context, e Event) error\n}\n\n\u002F\u002F Production: Service{now: time.Now, genID: uuid.NewString, publish: bus.Publish}\n\u002F\u002F Test:       Service{now: fixedTime, genID: constID, publish: capture}\n```\n\n## 5. When Frameworks Earn Their Complexity\n\nManual wiring scales further than expected — a 100-line `run` function\nis still readable and compiler-checked. Consider a tool when wiring\ncrosses hundreds of components or many teams share one binary.\n\n| Tool | Model | Trade-off |\n|---|---|---|\n| google\u002Fwire | Compile-time code generation | Wiring stays plain Go and compiler-checked; adds a codegen step |\n| uber-go\u002Ffx | Runtime container + lifecycle | App lifecycle (start\u002Fstop hooks) managed; errors surface at runtime, magic in stack traces |\n| uber-go\u002Fdig | Runtime container (fx's core) | Same runtime trade-offs, no lifecycle layer |\n\nDecision rule: prefer manual wiring; if generation becomes necessary\nprefer wire (failures at compile time beat failures at startup); adopt\nfx only when you also want its lifecycle management and your team\naccepts the runtime container.\n\nNever mix models: one composition root, one mechanism.\n\n## 6. Wire Example (when chosen)\n\n```go\n\u002F\u002Fgo:build wireinject\n\nfunc InitializeServer(cfg Config) (*handler.Server, error) {\n    wire.Build(\n        store.Open,\n        store.NewOrderRepo,\n        stripe.NewGateway,\n        service.NewOrderService,\n        handler.NewServer,\n    )\n    return nil, nil \u002F\u002F replaced by generated code\n}\n```\n\n`wire` generates the ordered constructor calls; the generated file is\ncommitted and reviewed like handwritten code.\n\n## Verification Checklist\n\n1. Every service\u002Fhandler receives dependencies via constructor parameters\n2. No package-level mutable singletons (`var DB`, `var logger`, `Get()` accessors)\n3. All wiring concentrated in main\u002Frun — no `init()` construction\n4. Dependencies accepted as interfaces (or funcs), concrete types returned\n5. Constructors validate required dependencies\n6. Components testable by passing fakes — no process-global setup in tests\n7. If a DI tool is used: exactly one, at the composition root only\n8. `go build .\u002F...` passes — wiring errors surface at compile time\n",{"name":5,"license":15,"metadata":24,"description":27,"allowed-tools":28,"compatibility":29,"user-invocable":30},{"author":25,"version":26},"eduardo-sl","1.1.1","Dependency injection in Go: constructor injection, wiring in main, avoiding global state, and when frameworks (wire, fx, dig) earn their complexity. Use when: \"dependency injection\", \"wire up dependencies\", \"inject this\", \"remove global state\", \"singleton in Go\", \"use google\u002Fwire\", \"uber fx\", \"make this testable\". Not for: interface design (go-interface-design), directory structure (go-project-layout), test doubles and mocks (go-test-quality).\n","Read Edit Write Glob Grep Bash(go:*) Bash(gofmt:*)","Designed for Claude Code or similar AI coding agents working on Go projects. Requires the Go toolchain. wire and fx are optional.",true,"main","19f4d52a98d557f3a645a2cfbbeb5bd54f28831d",".github\u002Fskills\u002Fgo-agent-skills\u002Fskills\u002F(architecture)\u002Fgo-dependency-injection","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi","https:\u002F\u002Fgithub.com\u002Fkongnakornna","http:\u002F\u002Fcmoniot.trueddns.com:52160","Technical Skills and Expertise\r\nLanguages and Frameworks\r\nFrontend: HTML, JavaScript, TypeScript, React, Vue, Angular, Next.js\r\nBackend: Node.js,Python,Golang","2026-10-06 23:01:46",{"source":8,"skillName":5,"commands":40,"prompt":50,"zipAvailable":30},[41,44,47],{"tool":42,"command":43},"npx","npx skills add kongnakornna\u002Fgolangapi --skill go-dependency-injection",{"tool":45,"command":46},"bunx","bunx skills add kongnakornna\u002Fgolangapi --skill go-dependency-injection",{"tool":48,"command":49},"pnpm","pnpm dlx skills add kongnakornna\u002Fgolangapi --skill go-dependency-injection","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Fgo-agent-skills\u002Fskills\u002F(architecture)\u002Fgo-dependency-injection\u002FSKILL.md",[],[53,61,68,75,82,89],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":57,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M7A0M9RJJ3383VEFYKABWV15","tb-writing-plans","Use when you have a spec or requirements for a multi-step task, before touching code","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-writing-plans\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":57,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M7A0M4JKY4DEDRP1CBHT00WV","tb-using-git-worktrees","Use when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallback","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-using-git-worktrees\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":57,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M7A0KZ5HRAQAAT2KXR6146Q7","tb-test-driven-development","Use when implementing any feature or bugfix, before writing implementation code","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-test-driven-development\u002FSKILL.md",[],[],{"skillNo":76,"name":77,"nameZh":6,"description":78,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":57,"licenseFileUrl":6,"sourceHtmlUrl":79,"categories":80,"keywords":81,"publishedAt":19},"01M7A0KW92W3F18E2MRP8H62P2","tb-subagent-driven-development","Use when executing implementation plans with independent tasks in the current session","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-subagent-driven-development\u002FSKILL.md",[],[],{"skillNo":83,"name":84,"nameZh":6,"description":85,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":57,"licenseFileUrl":6,"sourceHtmlUrl":86,"categories":87,"keywords":88,"publishedAt":19},"01M7A0KKYQCHYYRHA5J5BAP24M","tb-scrutinize","Outsider-perspective end-to-end review of a plan, PR, or code change. First questions intent and whether a simpler\u002Fmore elegant approach would achieve the same goal, then traces the actual code path (not just the diff) to verify the change does what it claims. Output is concise, actionable, and every call carries its rationale. Trigger on \u002Ftb-scrutinize and proactively whenever the user asks to review, audit, sanity-check, or get a second opinion on a plan, PR, diff, design doc, or proposed code change.","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-scrutinize\u002FSKILL.md",[],[],{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":57,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":19},"01M7A0KFDR1V3RW7SW1XNHP82P","tb-requesting-code-review","Use when completing tasks, implementing major features, or before merging to verify work meets requirements","https:\u002F\u002Fgithub.com\u002Fkongnakornna\u002Fgolangapi\u002Fblob\u002Fmain\u002F.github\u002Fskills\u002Ftb-requesting-code-review\u002FSKILL.md",[],[]]