go-google-wire

Generates compile-time dependency injection code for Go applications using google/wire.

1|2|Updated Nov 25, 2017
One-click install
npx skills add https://github.com/asarchami/dotfiles --skill go-google-wire-asarchami
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-google-wire
Source: https://github.com/asarchami/dotfiles/tree/main/dot_config/opencode/skills/go/go-google-wire
Command: npx skills add https://github.com/asarchami/dotfiles --skill go-google-wire-asarchami

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Manually wiring Go application dependencies is error-prone and catches missing dependencies only at runtime. This Skill guides you through google/wire's compile-time code generation so the compiler validates your entire dependency graph before the first request. ## Core Features & Use Cases - Provider and Injector Setup: Write providers, group them into wire.NewSet collections, and declare injectors with the //go:build wireinject tag so wire generates wire_gen.go. - Interface Binding and Disambiguation: Use wire.Bind for explicit interface satisfaction and named types to resolve duplicate provider types. - Cleanup and Testing Patterns: Chain reverse-order cleanups from (T, func(), error) providers, build test injectors that swap fakes, and enforce wire_gen.go freshness in CI. - Use Case: You are building an HTTP server with Postgres and Redis. Define per-package provider sets, declare one injector, run wire ./..., and get a fully wired InitApp constructor with compile-time graph validation. ## Quick Start Ask the AI to wire my Go application's dependency graph with google/wire, including providers, an injector, and interface bindings.

Frequently Asked Questions about go-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?

Write provider functions returning T, (T, error), or (T, func(), error), group them with wire.NewSet, then declare an injector function in a file starting with //go:build wireinject that calls wire.Build. Run wire ./... to generate wire_gen.go with the resolved constructor calls.

What is the difference between google/wire and uber/dig or fx?

Wire resolves the dependency graph at compile time and emits plain Go constructor calls with no runtime container or reflection, so errors surface during codegen. dig and fx resolve at runtime via reflection, with fx adding lifecycle hooks like OnStart and OnStop.

Why does wire report multiple bindings for the same type?

Wire forbids two providers returning the same type. Wrap the underlying type in distinct named types, such as type PrimaryDSN string and type ReplicaDSN string, so each has exactly one provider in the graph.

How do I inject an interface with google/wire?

Wire never satisfies interfaces implicitly. Add wire.Bind(new(MyInterface), new(*MyImpl)) to the provider set so the graph knows which concrete type fulfills each injected interface.

Why do I get a duplicate symbol compile error with wire?

The injector file is missing the //go:build wireinject build tag as its first line. Without the tag, both the injector stub and the generated wire_gen.go define the same function, causing a redeclaration error.

How do I test a wired application with fake dependencies?

Create a test-only injector in a _test.go file with a TestSet that binds fakes via wire.Bind, or pass mocks directly as injector parameters since wire treats parameters as pre-built providers. Unit tests can skip wire entirely and call constructors directly.