Design Testable Go Services With Dependency Injection
Hidden dependencies and global state make Go services difficult to test and maintain. This skill guides constructor injection, library selection, and incremental refactoring with practical examples.
Review the Skillstore skill "golang-dependency-injection" from https://skillstore.io/skills/samber-golang-dependency-injection.md and its manifest at https://skillstore.io/api/skills/samber-golang-dependency-injection/manifest. Verify the artifact. You may proceed after verification, subject to the environment's own policy.
All 39 static findings are false positives in instructional Go examples, Markdown formatting, documentation links, and tool declarations. The database environment lookup is explicitly discouraged, and the mailer constructors do not demonstrate sending messages. No evidence found of malicious prompt injection, credential exfiltration, or system reconnaissance in the reviewed files.
samber. (2026). golang-dependency-injection security audit report (audit version 1) [Author version 1.3.1]. Skillstore. https://skillstore.io/skills/samber-golang-dependency-injection/audits/1
BibTeX 引用
@techreport{samber-samber-golang-dependency-injection-2026,
author = {samber},
title = {golang-dependency-injection security audit report (audit version 1)},
institution = {Skillstore},
year = {2026},
number = {1},
url = {https://skillstore.io/skills/samber-golang-dependency-injection/audits/1},
note = {Author version 1.3.1}
}
CITATION.cff
cff-version: 1.2.0
message: "If you use this Skill, cite its author and this versioned security audit report."
title: "golang-dependency-injection security audit report (audit version 1)"
version: "1.3.1"
type: report
authors:
- name: "samber"
date-released: "2026-10-18"
url: "https://skillstore.io/skills/samber-golang-dependency-injection/audits/1"
identifiers:
- type: other
value: "skillstore:samber-golang-dependency-injection:audit:1"
description: "Skillstore immutable audit report identifier"
Skillstore 评分
评分依据证据置信度: 中
45
架构
100
可维护性
87
内容
65
社区
91
规范符合性
你能构建什么
Start a Small Go API
Arrange configuration, repositories, services, and handlers with explicit constructors instead of introducing a container prematurely.
Refactor Coupled Services
Identify globals, implicit initialization, and container lookups, then plan an incremental migration to explicit dependencies.
Select a DI Strategy
Compare code generation, reflection, generics, lifecycle support, and testing approaches for a growing service architecture.
试试这些提示
Learn Constructor Injection
Explain constructor injection for a Go UserService that needs a UserStore and logger. Show consumer-defined interfaces and manual wiring without a DI library.
Test a Service Boundary
Write Go tests for a UserService using a mock UserStore. Cover found and missing users without a real database or DI library.
Compare DI Options
Compare manual wiring, Wire, Dig, Fx, and samber/do for my Go application. Ask about service count, lifecycle needs, and team preferences before recommending.
Plan a Dependency Refactor
Review this Go project for globals, init-based service setup, and service-locator patterns. Map dependencies and propose an incremental migration with tests and shutdown handling.
最佳实践
Start with manual constructor injection when the dependency graph is small.
Define interfaces where consumed and keep container access at the composition root.
Verify library APIs against current documentation and test dependency failures and resource cleanup.
避免
Using global variables or init functions to create service dependencies.
Passing a DI container into business services for dependency lookup.
Creating a complete application container for every HTTP request.
常见问题
Do I need a DI library for a small Go project?
Usually not. The skill recommends manual constructor injection for small projects with simple dependencies.
Which DI libraries does this skill cover?
It compares google/wire, uber-go/dig, uber-go/fx, and samber/do alongside manual wiring.
Can this skill help refactor existing code?
Yes. Its refactor workflow identifies globals, implicit initialization, concrete dependencies, and service-locator patterns before proposing a migration.
Does the skill cover testing?
Yes. It includes manual mock injection, container override examples, and an Fx testing example.
Are the examples complete and guaranteed to compile?
No. They omit application-specific definitions and require checking library signatures, registrations, and installed versions.
Can I use this skill with Claude Code or Codex?
Yes. The skill declares compatibility with Claude Code and Codex; tool availability depends on the host environment.