external/cc-skills-golang/golang-samber-do/SKILL.md
Dependency injection in Golang using samber/do — service containers, lifecycle management, scopes, health checks, graceful shutdown, and module organization. Apply when using or adopting samber/do, when the codebase imports github.com/samber/do or github.com/samber/do/v2, or when refactoring manual constructor injection into a DI container.
npx skillsauth add seikaikyo/dash-skills golang-samber-doInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Persona: You are a Go architect setting up dependency injection. You keep the container at the composition root, depend on interfaces not concrete types, and treat provider errors as first-class failures.
Type-safe dependency injection toolkit for Go based on Go 1.18+ generics.
Official Resources:
This skill is not exhaustive. Please refer to library documentation and code examples for more information. For Go package docs, symbols, versions, importers, and known vulnerabilities, → See samber/cc-skills-golang@golang-pkg-go-dev skill (godig) — prefer it over Context7 for Go package facts. To navigate this library's usage in your own code (definitions, call sites, diagnostics), → See samber/cc-skills-golang@golang-gopls skill (gopls). Context7 remains a fallback for docs not indexed on pkg.go.dev.
DO NOT USE v1 OF THIS LIBRARY. INSTALL v2 INSTEAD:
go get -u github.com/samber/do/v2
import "github.com/samber/do/v2"
injector := do.New()
Services MUST be registered via provider functions:
type Provider[T any] func(i Injector) (T, error)
Follow "Accept Interfaces, Return Structs":
// Register a service (lazy by default)
do.Provide(injector, func(i do.Injector) (Database, error) {
return &PostgreSQLDatabase{connString: "postgres://..."}, nil
})
// Register a pre-created value
do.ProvideValue(injector, &Config{Port: 8080})
// Register a transient service (new instance each time)
do.ProvideTransient(injector, func(i do.Injector) (*Logger, error) {
return &Logger{}, nil
})
// Register an eager service (created immediately at startup)
do.ProvideValue(injector, &Config{Port: 8080})
The container MUST only be accessed at the composition root:
// Invoke with error handling — reserve for call sites outside the DI graph
// (e.g. an HTTP handler that must degrade gracefully instead of crashing)
db, err := do.Invoke[Database](injector)
// MustInvoke panics on error — preferred in providers, recovered by do.Invoke on the parent call
db := do.MustInvoke[Database](injector)
Inside a provider function, always use do.MustInvoke (or MustInvokeAs/MustInvokeNamed/MustInvokeStruct) rather than the error-returning variant. A provider already returns (T, error), so propagating a dependency failure with do.Invoke costs an extra if err != nil { return nil, err } on every call. do.MustInvoke panics instead, but samber/do correctly catches and recovers that panic at the enclosing Invoke call and converts it back into a regular error — this recover happens inside the library itself, not in caller code, so MustInvoke is safe to use inside providers. The failure still surfaces as an error at the composition root, just without the manual boilerplate in every provider.
func NewUserService(i do.Injector) (UserService, error) {
db := do.MustInvoke[Database](i)
cache := do.MustInvoke[Cache](i)
return &userService{db: db, cache: cache}, nil
}
do.Provide(injector, NewUserService)
Register a concrete type and invoke as an interface without explicit aliasing:
// Register concrete type
do.Provide(injector, func(i do.Injector) (*PostgreSQLDatabase, error) {
return &PostgreSQLDatabase{}, nil
})
// Invoke directly as interface (implicit aliasing)
db := do.MustInvokeAs[Database](injector)
Register multiple services of the same type:
do.ProvideNamed(injector, "primary-db", func(i do.Injector) (*Database, error) {
return &Database{URL: "postgres://primary..."}, nil
})
mainDB := do.MustInvokeNamed[*Database](injector, "primary-db")
Use do.Package() to organize service registration by module:
// infrastructure/package.go
var Package = do.Package(
do.Lazy(func(i do.Injector) (*postgres.DB, error) {
cfg := do.MustInvoke[*Config](i)
return postgres.Connect(cfg.DatabaseURL)
}),
do.Lazy(func(i do.Injector) (*redis.Client, error) {
cfg := do.MustInvoke[*Config](i)
return redis.NewClient(cfg.RedisURL), nil
}),
)
// main.go
injector := do.New(infrastructure.Package, service.Package)
func main() {
injector := do.New(
infrastructure.Package,
repository.Package,
service.Package,
transport.Package,
)
server := do.MustInvoke[*http.Server](injector)
go server.ListenAndServe()
_ = injector.ShutdownOnSignalsWithContext(context.Background(), os.Interrupt)
}
do.MustInvoke* inside provider functions instead of do.Invoke* — samber/do correctly catches and recovers the panic at the outer Invoke call, turning it back into a returned error, so it's safe to use inside providers and you get the same error propagation without the boilerplateFor scopes, lifecycle management, struct injection, and debugging, see Advanced Usage.
For testing patterns (cloning, overrides, mocks), see Testing.
| Function | Purpose |
| ------------------------------- | -------------------------------- |
| do.Provide[T]() | Register lazy service (default) |
| do.ProvideNamed[T]() | Register named lazy service |
| do.ProvideValue[T]() | Register pre-created value |
| do.ProvideNamedValue[T]() | Register named value |
| do.ProvideTransient[T]() | Register new instance each time |
| do.ProvideNamedTransient[T]() | Register named transient service |
| do.Package() | Group service registrations |
| Function | Purpose |
| -------------------------- | ----------------------------------------- |
| do.Invoke[T]() | Get service (with error) |
| do.InvokeNamed[T]() | Get named service |
| do.InvokeAs[T]() | Get first service matching interface |
| do.InvokeStruct[T]() | Inject into struct fields using tags |
| do.MustInvoke[T]() | Get service (panic on error) |
| do.MustInvokeNamed[T]() | Get named service (panic on error) |
| do.MustInvokeAs[T]() | Get service by interface (panic on error) |
| do.MustInvokeStruct[T]() | Inject into struct (panic on error) |
samber/cc-skills-golang@golang-dependency-injection skill for DI concepts, comparison, and when to adopt a DI librarysamber/cc-skills-golang@golang-structs-interfaces skill for interface design patternssamber/cc-skills-golang@golang-testing skill for general testing patternstools
Conduct comprehensive GDPR compliance assessments by evaluating data processing activities against EU Regulation 2016/679, including Article 30 records of processing, lawful basis validation, data subject rights implementation, Data Protection Impact Assessments (DPIAs) under Article 35, breach notification procedures, international transfer safeguards (SCCs, adequacy decisions), and technical/organizational measures under Article 32. Use when processing personal data of EU residents, preparing for supervisory authority audits, implementing privacy-by-design for new systems, scoping compliance gaps for M&A due diligence, assessing third-party processors, or responding to data subject access requests at scale. Incorporates 2026 guidance from ICO, EDPB, and post-Data (Use and Access) Act 2025 UK-GDPR considerations. Do not use for implementing specific Article 32 controls — use implementing-gdpr-data-protection-controls; or for DSAR automation — use implementing-gdpr-data-subject-access-request.
tools
Parse Windows forensic artifacts—$MFT/$J (MFTECmd), Prefetch (PECmd), registry hives (RECmd), shellbags, and Amcache—into normalized CSV/JSON with Eric Zimmerman's EZ Tools, then load results into Timeline Explorer for analysis. Use during DFIR/incident-response investigations, after triage collection (e.g. with KAPE), to establish program execution, file/folder access, and persistence evidence from acquired forensic images.
development
Build automated multi-turn adversarial attacks against conversational LLM targets using Microsoft PyRIT's RedTeamingOrchestrator, CrescendoOrchestrator (gradual escalation), and TreeOfAttacksWithPruningOrchestrator (adaptive branching), with scorer feedback loops and persisted conversation memory. Use when single-shot LLM scanning is insufficient and you need multi-turn, scorer-driven AI red-team campaigns against a chatbot or agent.
testing
Stand up MISP, enable and cache curated threat feeds (CIRCL, abuse.ch, Feodo Tracker), apply warninglists to suppress false positives, query indicators with PyMISP, and export attributes as auto-generated Suricata/Sigma/Wazuh detection rules. Use when maturing a MISP instance to actively drive detection, curating threat feeds with quality controls, or automating IOC-to-detection pipelines for the SIEM/IDS.