How google/wire works
Wire is a Go compile-time dependency-injection code generator, not a runtime container. A developer declares providers and injector templates, then runs the wire CLI; the tool analyzes dependency requirements and emits Go initialization code, which the application builds and calls. The README documents provider sets, explicit function-parameter dependencies, and the absence of runtime reflection/state. Some internal stage boundaries are inferred from the partial excerpts, so those relationships are dashed and uncited rather than asserted as inspected calls.
Main entry points: wire.go Generation engine · main.go Wire CLI · parse.go Package analysis · analyze.go Provider graph
Components 11
Injector authoring
- Wire directives
wire.go - Injector template
wire.go
Generation command
- Wire CLI
cmd/wire/main.go
Analysis and emission
- Generation engine
internal/wire/wire.go - Package analysis
internal/wire/parse.go - Provider graph
internal/wire/analyze.go - Error reporting
internal/wire/errors.go - AST copying
internal/wire/copyast.go
Other components
- Go developer
- Generated injector
- Go application
Connections 11
- Go developer → Wire directives: declares providers
wire.go - Go developer → Injector template: writes template
wire.go - Go developer → Wire CLI: runs generation
README.md - Wire CLI → Generation engine: calls Generate
cmd/wire/main.go - Generation engine → Package analysis: analyzes packages
- Package analysis → Provider graph: builds provider graph
- Generation engine → Provider graph: solves dependencies
- Generation engine → Error reporting: collects errors
- Generation engine → AST copying: copies AST
internal/wire/wire.go - Generation engine → Generated injector: emits Go code
internal/wire/wire.go - Generated injector → Go application: compiled into
README.md