golang-google-wire
Compile-time dependency injection in Golang using google/wire — wire.NewSet, wire.Build, wire.Bind (interface→concrete), wire.Struct, wire.Value, wire.InterfaceValue, wire.FieldsOf, cleanup functions, //go:build wireinject injector files, and generated wire_gen.go. Apply when using or adopting google/wire, when the codebase imports `github.com/google/wire`, or when wiring an application graph at compile time via `wire.Build`. For runtime DI with reflection, see `samber/cc-skills-golang@golang-uber-dig` skill.
Rank
62
Safety
84
Downloads
1.2k
Updated
Oct 11, 2026
Version
1.1.0
Source
CLAWHUB
About
What it does, and when to use it.
Capability contract not published. No trust telemetry is available yet. 1.2K downloads reported by the source. Last updated 10/11/2026.
Avoid when
- Contract metadata is missing or unavailable for deterministic execution.
Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing
Public facts
Every fact links back to the source it came from.
- Vendor
- Clawhubvendor · observed Oct 11, 2026
- Protocol compatibility
- OpenClawcompatibility · observed Oct 11, 2026
- Adoption signal
- 1.2K downloadsadoption · observed Oct 11, 2026
- Latest release
- 1.1.0release · observed Aug 21, 2026
- Handshake status
- UNKNOWNsecurity
Install and run
Setup complexity: low.
clawhub skill install s173arkhs3131fq5jf769qq75583hdgt:golang-google-wire- Install using `clawhub skill install s173arkhs3131fq5jf769qq75583hdgt:golang-google-wire` in an isolated environment before connecting it to live workloads.
- No published capability contract is available yet, so validate auth and request/response behavior manually.
- Review the upstream CLAWHUB listing at https://clawhub.ai/samber/golang-google-wire before using production credentials.
Contract: missing
curl -s "https://www.xpersona.co/api/v1/agents/clawhub-samber-golang-google-wire/snapshot"
Documentation
CLAWHUB
143,991 characters of source documentation, loaded on request.
Extracted files
5 files captured from the source.
SKILL.md
---
name: golang-google-wire
description: "Compile-time dependency injection in Golang using google/wire — wire.NewSet, wire.Build, wire.Bind (interface→concrete), wire.Struct, wire.Value, wire.InterfaceValue, wire.FieldsOf, cleanup functions, //go:build wireinject injector files, and generated wire_gen.go. Apply when using or adopting google/wire, when the codebase imports `github.com/google/wire`, or when wiring an application graph at compile time via `wire.Build`. For runtime DI with reflection, see `samber/cc-skills-golang@golang-uber-dig` skill."
user-invocable: true
license: MIT
compatibility: Designed for Claude Code, Codex or similar harness, and for projects using Golang.
metadata:
author: samber
version: "1.1.0"
openclaw:
emoji: "🪡"
homepage: https://github.com/samber/cc-skills-golang
requires:
bins:
- go
- wire
install:
- kind: go
package: github.com/google/wire/cmd/wire@latest
bins: [wire]
skill-library-version: "0.7.0"
allowed-tools: Read Edit Write Glob Grep Bash(go:*) Bash(golangci-lint:*) Bash(git:*) Agent WebFetch mcp__context7__resolve-library-id mcp__context7__query-docs Bash(wire:*) Bash(godig:*) Bash(gopls:*) LSP mcp__gopls__*
paths:
- "**/*.go"
---
**Persona:** You are a Go architect using wire for compile-time DI. You let the compiler catch missing dependencies, treat `wire_gen.go` as committed source, and re-run `wire ./...` after every graph change.
**Dependencies:**
- wire: `go install github.com/google/wire/cmd/wire@latest`
# Using google/wire for Compile-Time Dependency Injection in Go
Code-generation DI toolkit. Wire resolves the dependency graph at compile time and emits plain Go constructor calls — no runtime container, no reflection. Errors appear when you run `wire ./...`, not at first request.
Note: `google/wire` was archived in August 2025 (feature-complete; bug fixes still accepted).
**Official Resources:** [pkg.go.dev](https://pkg.go.dev/github.com/google/wire) · [github.com/google/wire](https://github.com/google/wire) · [User Guide](https://github.com/google/wire/blob/main/docs/guide.md) · [Best Practices](https://github.com/google/wire/blob/main/docs/best-practices.md)
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.
```bash
go get -tool github.com/google/wire/cmd/wire@latest
go get github.com/google/wire
```
## wire vs. Runtime DI
| Concern | wire | dig / fx / samber/do |
| ----------------- | ------------------------- | ------------_meta.json
{
"ownerId": "kn72rhnkwjfeex9wr1n7y24qa983cjn3",
"slug": "golang-google-wire",
"version": "1.1.0",
"publishedAt": 1787280159519
}references/advanced.md
# Advanced — google/wire
Detail topics referenced from `SKILL.md`. Each section is self-contained.
## Cleanup Chains
When a provider returns `(T, func(), error)`, Wire adds the cleanup to a chain. The generated injector runs cleanups in **reverse construction order**: the last-built dependant is cleaned up first, ensuring dependants are torn down before their dependencies.
```go
// Provider with cleanup
func NewDB(cfg *Config) (*sql.DB, func(), error) {
db, err := sql.Open("postgres", string(cfg.DSN))
if err != nil { return nil, nil, err }
return db, func() { db.Close() }, nil
}
func NewCache(cfg *Config) (*redis.Client, func(), error) {
c := redis.NewClient(&redis.Options{Addr: cfg.CacheAddr})
return c, func() { c.Close() }, nil
}
```
Wire generates something like:
```go
func InitApp() (*App, func(), error) {
cfg := NewConfig()
db, dbCleanup, err := NewDB(cfg)
if err != nil { return nil, nil, err }
cache, cacheCleanup, err := NewCache(cfg)
if err != nil {
dbCleanup() // already-built cleanups run on partial failure
return nil, nil, err
}
app := NewApp(db, cache)
return app, func() {
cacheCleanup() // reverse order
dbCleanup()
}, nil
}
```
**Caller pattern** — guard against nil cleanup on construction failure:
```go
app, cleanup, err := InitApp()
if err != nil { log.Fatal(err) }
defer cleanup()
```
Wire always returns a non-nil cleanup function when construction succeeds. If construction fails midway, the returned `cleanup` is nil — guard before calling.
## Multiple Injectors in One Package
A package can contain multiple injector functions. Each must live in a file with `//go:build wireinject`. All generated functions land in `wire_gen.go` in the same package.
```go
//go:build wireinject
package main
// Production injector
func InitProdApp() (*App, func(), error) {
wire.Build(ProdSet, NewApp)
return nil, nil, nil
}
// Development injector with debug providers
func InitDevApp() (*App, func(), error) {
wire.Build(DevSet, NewApp)
return nil, nil, nil
}
```
Select at runtime with a flag, or at build time with separate `//go:build prod` / `//go:build !prod` constraints on the injector files.
## wire.NewSet Nesting Strategies
Sets can contain other sets, building a hierarchy that mirrors your package structure.
```go
// pkg/config/wire.go
var ConfigSet = wire.NewSet(NewConfig)
// pkg/infra/wire.go
var InfraSet = wire.NewSet(
config.ConfigSet, // embed upstream set
NewDB,
NewCache,
)
// pkg/service/wire.go
var ServiceSet = wire.NewSet(
NewUserService,
wire.Bind(new(UserStore), new(*UserRepo)),
)
// wire.go (injector)
wire.Build(infra.InfraSet, service.ServiceSet, NewApp)
```
**Library set stability rules** (from upstream best practices):
- Safe: replace one provider with another that has the same or fewer inputs, in the same release.
- Safe: introduce a brand-new output type not previously provided.
- Brereferences/recipes.md
# Recipes — google/wire
End-to-end examples. Each recipe is self-contained.
## HTTP Server with Postgres and Redis
A typical service: parsed config → DB (with cleanup) → Redis (with cleanup) → repo → service → HTTP server.
```
myapp/
├── config/
│ ├── config.go
│ └── wire.go
├── infra/
│ ├── db.go
│ ├── cache.go
│ └── wire.go
├── repo/
│ ├── user.go
│ └── wire.go
├── service/
│ ├── user.go
│ └── wire.go
├── transport/
│ ├── handler.go
│ └── wire.go
├── wire.go // injector — //go:build wireinject
├── wire_gen.go // generated — commit this
└── main.go
```
```go
// config/config.go
type Config struct {
Addr string
DSN string
CacheAddr string
}
func NewConfig() *Config {
return &Config{
Addr: env("ADDR", ":8080"),
DSN: mustEnv("DATABASE_URL"),
CacheAddr: env("REDIS_ADDR", "localhost:6379"),
}
}
// config/wire.go
var ConfigSet = wire.NewSet(NewConfig)
```
```go
// infra/db.go
func NewDB(cfg *config.Config) (*sql.DB, func(), error) {
db, err := sql.Open("postgres", cfg.DSN)
if err != nil { return nil, nil, err }
if err := db.Ping(); err != nil { db.Close(); return nil, nil, err }
return db, func() { db.Close() }, nil
}
// infra/cache.go
func NewRedis(cfg *config.Config) (*redis.Client, func(), error) {
c := redis.NewClient(&redis.Options{Addr: cfg.CacheAddr})
if err := c.Ping(context.Background()).Err(); err != nil {
return nil, nil, err
}
return c, func() { c.Close() }, nil
}
// infra/wire.go
var InfraSet = wire.NewSet(NewDB, NewRedis)
```
```go
// repo/user.go
type UserStore interface {
GetUser(ctx context.Context, id int64) (*User, error)
}
type PostgresUserRepo struct{ db *sql.DB }
func NewUserRepo(db *sql.DB) *PostgresUserRepo { return &PostgresUserRepo{db: db} }
// repo/wire.go
var RepoSet = wire.NewSet(
NewUserRepo,
wire.Bind(new(UserStore), new(*PostgresUserRepo)),
)
```
```go
// service/user.go
type UserService struct {
store repo.UserStore
cache *redis.Client
}
func NewUserService(store repo.UserStore, cache *redis.Client) *UserService {
return &UserService{store: store, cache: cache}
}
// service/wire.go
var ServiceSet = wire.NewSet(NewUserService)
```
```go
// wire.go
//go:build wireinject
package main
func InitApp() (*transport.Handler, func(), error) {
wire.Build(
config.ConfigSet,
infra.InfraSet,
repo.RepoSet,
service.ServiceSet,
transport.NewHandler,
)
return nil, nil, nil
}
```
```go
// main.go
func main() {
handler, cleanup, err := InitApp()
if err != nil { log.Fatal(err) }
defer cleanup()
srv := &http.Server{Addr: ":8080", Handler: handler}
log.Fatal(srv.ListenAndServe())
}
```
## Multiple Build Variants (Prod vs Dev)
Use separate injector files with `//go:build` constraints to select different provider sets at build time.
```go
// wire_prod.go
//go:build wireinject && !dev
pareferences/testing.md
# Testing — google/wire
Wire generates plain Go constructor calls, so tests work directly on the constructor layer — no container API to learn.
## Unit Tests: Plain Constructor Injection
The generated code has no wire dependency. Test constructors directly:
```go
func TestUserService_GetUser(t *testing.T) {
mockStore := &MockUserStore{users: map[int64]*User{1: &User{ID: 1, Name: "Alice"}}}
cache := newTestRedis(t)
svc := service.NewUserService(mockStore, cache)
u, err := svc.GetUser(context.Background(), 1)
require.NoError(t, err)
assert.Equal(t, "Alice", u.Name)
}
```
Pass mocks directly as constructor arguments. No wire, no container, no file to generate. This is the idiomatic approach for unit tests.
## Test Injectors: Swapping Providers
For integration or component tests where you want the full wired graph but with selected dependencies replaced, create a test-only injector in a `_test.go` file.
```go
// app_test.go
//go:build wireinject
package main
import (
"testing"
"github.com/google/wire"
)
// TestSet replaces real infra with in-memory fakes
var TestSet = wire.NewSet(
NewTestConfig,
NewInMemoryUserStore,
wire.Bind(new(repo.UserStore), new(*InMemoryUserStore)),
NewTestRedis,
)
func InitTestApp(t *testing.T) (*App, func(), error) {
wire.Build(TestSet, service.ServiceSet, NewApp)
return nil, nil, nil
}
```
```go
// app_integration_test.go
//go:build !wireinject // compiles when the wireinject tag is NOT set
package main
func TestApp_GetUser(t *testing.T) {
app, cleanup, err := InitTestApp(t)
require.NoError(t, err)
defer cleanup()
// test against the fully-wired app with fake dependencies
u, err := app.GetUser(context.Background(), 1)
require.NoError(t, err)
assert.NotNil(t, u)
}
```
Run `wire ./...` to generate `wire_gen.go` — the test injector is included because the `_test.go` file is compiled as part of the package during `go test`.
**Key pattern from upstream best practices:** Prefer creating a test-only provider set over passing mocks as injector arguments (though both work). The set approach keeps the test injector composable.
## Passing Mocks as Injector Arguments
An alternative to a test set: pass the mock directly as an injector parameter. Wire treats it as a pre-built provider.
```go
//go:build wireinject
func InitTestApp(store repo.UserStore) (*App, func(), error) {
wire.Build(config.ConfigSet, service.ServiceSet, NewApp)
return nil, nil, nil
}
// Test
func TestApp(t *testing.T) {
mock := &MockUserStore{}
app, cleanup, err := InitTestApp(mock)
require.NoError(t, err)
defer cleanup()
// ...
}
```
Use this form when you only need to replace one or two dependencies and a full `TestSet` is overkill.
## CI: Detecting Stale `wire_gen.go`
If `wire_gen.go` is not regenerated after a provider change, CI builds pass but the graph is wrong. Enforce freshness in CI:
```bash
# Option 1: re-run wire and AionUi
Free, local, open-source 24/7 Cowork app and OpenClaw for Gemini CLI, Claude Code, Codex, OpenCode, Qwen Code, Goose CLI, Auggie, and more | 🌟 Star if you like it!
activepieces
AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
cherry-studio
AI productivity studio with smart chat, autonomous agents, and 300+ assistants.
CopilotKit
The Frontend for Agents & Generative UI. React + Angular
Machine-readable data
The same record, as JSON, for agents and crawlers.
{
"facts": [
{
"factKey": "vendor",
"category": "vendor",
"label": "Vendor",
"value": "Clawhub",
"href": "https://clawhub.ai/samber/skills/golang-google-wire",
"sourceUrl": "https://clawhub.ai/samber/skills/golang-google-wire",
"sourceType": "profile",
"confidence": "medium",
"observedAt": "2026-10-11T04:37:47.996Z",
"isPublic": true
},
{
"factKey": "protocols",
"category": "compatibility",
"label": "Protocol compatibility",
"value": "OpenClaw",
"href": "https://www.xpersona.co/api/v1/agents/clawhub-samber-golang-google-wire/contract",
"sourceUrl": "https://www.xpersona.co/api/v1/agents/clawhub-samber-golang-google-wire/contract",
"sourceType": "contract",
"confidence": "medium",
"observedAt": "2026-10-11T04:37:47.996Z",
"isPublic": true
},
{
"factKey": "traction",
"category": "adoption",
"label": "Adoption signal",
"value": "1.2K downloads",
"href": "https://clawhub.ai/samber/golang-google-wire",
"sourceUrl": "https://clawhub.ai/samber/golang-google-wire",
"sourceType": "profile",
"confidence": "medium",
"observedAt": "2026-10-11T04:37:47.996Z",
"isPublic": true
},
{
"factKey": "latest_release",
"category": "release",
"label": "Latest release",
"value": "1.1.0",
"href": "https://clawhub.ai/samber/golang-google-wire",
"sourceUrl": "https://clawhub.ai/samber/golang-google-wire",
"sourceType": "release",
"confidence": "medium",
"observedAt": "2026-08-21T02:42:39.519Z",
"isPublic": true
},
{
"factKey": "handshake_status",
"category": "security",
"label": "Handshake status",
"value": "UNKNOWN",
"href": "https://www.xpersona.co/api/v1/agents/clawhub-samber-golang-google-wire/trust",
"sourceUrl": "https://www.xpersona.co/api/v1/agents/clawhub-samber-golang-google-wire/trust",
"sourceType": "trust",
"confidence": "medium",
"observedAt": null,
"isPublic": true
}
],
"events": [
{
"eventType": "release",
"title": "Release 1.1.0",
"description": "golang-google-wire 1.1.0 - Added support for new harnesses and tooling (Codex, gopls, godig). - Expanded documentation with pointers to `pkg.go.dev` and related skills for Go package details and code navigation. - Updated compatibility and metadata, including new `paths` and allowed tools (e.g., Bash(godig:*), Bash(gopls:*), LSP). - Removed legacy `skill-card.md`, streamlining documentation. - Improved guidance on how to prefer skills for code analysis and navigation.",
"href": "https://clawhub.ai/samber/golang-google-wire",
"sourceUrl": "https://clawhub.ai/samber/golang-google-wire",
"sourceType": "release",
"confidence": "medium",
"observedAt": "2026-08-21T02:42:39.519Z",
"isPublic": true
}
]
}Record generated Oct 11, 2026.
