golang-google-wire

Implements compile-time dependency injection in Go using google/wire code generation.

Updated Jun 30, 2026
One-click install
npx skills add https://github.com/santoshkal/chezmoi --skill golang-google-wire-santoshkal
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: golang-google-wire
Source: https://github.com/santoshkal/chezmoi/tree/main/private_dot_config/opencode/skills/Golang/skills/golang-google-wire
Command: npx skills add https://github.com/santoshkal/chezmoi --skill golang-google-wire-santoshkal

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires github.com/google/wire, and includes references (resource) components.

What problem does it solve? Manually wiring Go application dependencies is error-prone and runtime DI containers hide errors until startup. This Skill guides you through google/wire, which resolves the dependency graph at compile time and generates plain Go constructor calls, so missing dependencies surface as build errors instead of runtime failures. ## Core Features & Use Cases - Provider Sets and Injectors: Organize constructors into per-package wire.NewSet groups and declare injectors with wire.Build behind the //go:build wireinject tag. - Interface Bindings and Struct Injection: Map interfaces to concrete types with wire.Bind, fill struct fields with wire.Struct, and promote config fields with wire.FieldsOf. - Cleanup Chains and Testing: Return (T, func(), error) from providers so wire chains shutdown in reverse order, and build test injectors that swap real providers for fakes. - Use Case: You are building an HTTP service with Postgres, Redis, and layered repositories. Define per-package provider sets, run wire ./..., and commit the generated wire_gen.go so CI builds a fully wired app with compile-time safety. ## Quick Start Ask the AI to set up google/wire dependency injection for your Go service with per-package provider sets, an injector file, and cleanup functions for database connections.

Frequently Asked Questions about golang-google-wire

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up google/wire dependency injection in Go?▼

Install the wire CLI with go install github.com/google/wire/cmd/wire@latest, define providers as functions returning your types, group them with wire.NewSet, and declare an injector calling wire.Build in a file tagged //go:build wireinject. Run wire ./... to generate wire_gen.go.

google/wire vs uber/fx: which DI framework should I use?▼

Wire resolves dependencies at compile time with code generation and no runtime container, while fx uses runtime reflection with lifecycle hooks like OnStart/OnStop and signal handling. Choose wire for compile-time safety; choose fx for long-running daemons needing graceful shutdown.

Why does wire report 'no provider found' for my interface?▼

Wire never auto-resolves interface satisfaction; bindings must be explicit. Add wire.Bind(new(MyInterface), new(*MyImpl)) to the provider set so wire knows which concrete type satisfies the interface.

Why do I get 'redeclared in this block' after running wire?▼

The injector file is missing the //go:build wireinject build tag, so both the stub and the generated wire_gen.go define the same function. Add the tag as the first line of the injector file so only the generated file compiles.

How do I inject two values of the same type with wire?▼

Wire enforces one provider per type, so wrap the underlying type in distinct named types such as type PrimaryDSN string and type ReplicaDSN string. Update the providers and consumers to use the named types.

Should I edit wire_gen.go to fix build errors?▼

Never edit wire_gen.go because it is overwritten on every wire run. Fix the provider or injector source, ensure all dependencies are provided in the graph, then re-run wire ./... to regenerate it.