matdev83/golang-curated-agent-skills/golang-samber-do

Claude Code and agent skill by matdev83/golang-curated-agent-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Use samber/do/v2 for explicit generic dependency injection, scopes, lazy and transient providers, lifecycle checks, cloning, and shutdown.

Install

npx vskill@latest install matdev83/golang-curated-agent-skills/golang-samber-do

SKILL.md

The same SKILL.md was published earlier as matdev83/golang-curated-agent-skills/golang-samber-do.

samber/do/v2

This skill targets the v2 module path github.com/samber/do/v2. Pin the version in the consuming module and verify the API against that version. Use a manual composition root when the graph is small enough to read directly.

Registration and invocation

Providers receive do.Injector and return a value plus an error when construction can fail:

~~~go package main

import ( "fmt" do "github.com/samber/do/v2" )

type Config struct{ Address string } type Server struct{ address string }

func newServer(i do.Injector) (*Server, error) { cfg, err := do.InvokeConfig if err != nil { return nil, fmt.Errorf("resolve config: %w", err) } return &Server{address: cfg.Address}, nil }

func main() { injector := do.New() do.ProvideValue(injector, Config{Address: ":8080"}) do.Provide(injector, newServer) server, err := do.Invoke*Server _ = server _ = err } ~~~

Provide is lazy unless the selected API says otherwise. Use ProvideTransient when each Invoke should construct a fresh value. Use ProvideNamed/InvokeNamed for multiple registrations of the same type. Eager service helpers are registration options in the library's current API; they are not providers and cannot be passed as if they were provider functions.

Resolution failures, missing services, and circular dependencies are runtime errors. The type parameter improves the result type but does not make the graph compiler-checked.

Scopes and lifetimes

Create a child with injector.Scope("name", optionalPackageFunctions...). A child can resolve ancestor services; an ancestor cannot resolve child-only services. Register request or tenant resources in a scope that has the same lifetime and shut it down when that lifetime ends.

RootScope.Clone returns a cloned injector for isolated tests. It copies the container graph according to library semantics; it does not clone network connections, files, goroutines, or arbitrary values held by providers. Prefer fresh construction for tests when external resources are involved.

Lifecycle

Services can implement the library's health-check and shutdown interfaces (including context-aware variants). HealthCheck and Shutdown return the library's reported errors; ShutdownWithContext bounds cleanup. Treat shutdown as an application lifecycle phase and still make individual resources idempotently closable.

Do not store request contexts in services. Hooks can observe registration, invocation, and shutdown, but they should not hide business logic or mutate global state. Add logging/metrics through explicit hooks or an adapter with a documented failure policy.

Testing

Create a fresh root per test. Register test values or OverrideValue/Override providers before invoking the service. Assert missing, circular, and constructor errors as well as successful resolution. Use injector.Clone only through the current RootScope method when a clone is truly useful, and shut down the test injector with a bounded context.

For production review, inspect provider signatures, lazy versus transient semantics, scope ownership, shutdown ordering, external resource cleanup, and whether direct constructors would be clearer. Check API names in the pinned module before copying examples.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/matdev83/golang-curated-agent-skills/golang-samber-do/badge)](https://verified-skill.com/skills/matdev83/golang-curated-agent-skills/golang-samber-do)

Something wrong with this skill or its page? Tell us.