gitmyhub

wire

Go ★ 14k updated 10mo ago ▣ archived

Compile-time Dependency Injection for Go

Google's code generation tool for Go that reads how your program's components depend on each other and writes the boilerplate startup wiring code automatically.

Gosetup: moderatecomplexity 3/5

Wire is a code generation tool for the Go programming language, created by Google, that solves a common problem in software development called dependency injection. Dependency injection is a technique where the pieces of a program are wired together explicitly, so each component receives the other components it needs rather than creating them itself or reaching for shared global variables. This makes programs easier to test and reason about, because the connections between parts are visible and explicit.

The main job of Wire is to automate the repetitive work of writing that wiring code. You describe which components depend on which others, and Wire reads those descriptions and generates the Go code that sets everything up in the correct order at startup. Because Wire produces plain Go code, you can read and understand what it generates without any special tools, and it works without any runtime overhead or use of reflection (a technique where a program inspects its own structure at run time, which can be slower and harder to debug).

Wire is considered feature-complete, meaning the core functionality is done and no new features are being added. The project's own README notes that it is no longer actively maintained, and users who want to extend it are directed to create their own fork (a personal copy of the project that they control). Bug reports and fixes were still accepted as of the last update, but new feature requests were not.

The project is written in Go and is distributed as a command-line tool. Documentation including a tutorial, a user guide, and a best practices document are included in the repository. Community questions can be asked through GitHub Discussions.

Where it fits