kibuwire
kibuwire - Dependency Injection Provider Registration
kibuwire analyzes Go code for provider annotations and generates Google Wire dependency injection configuration files. It automates the tedious process of managing Wire sets across large codebases.
Installation
go install github.com/kibu-sh/kibu/internal/toolchain/kibuwire/cmd/kibuwire@maingo install github.com/google/wire/cmd/wire@latestPurpose
kibuwire solves the problem of managing Wire provider sets at scale by:
- Scanning for
//kibu:providerdecorators on functions, structs, and variables - Extracting provider metadata including group assignments and import paths
- Generating organized Wire sets by group and package
- Creating a SuperSet that combines all providers for easy injection
Usage
Add a go:generate directive to your project:
package generate
//go:generate kibuwire ./...Then run:
go generate ./...This produces kibuwire/kibuwire.gen.go containing all Wire sets.
The Provider Decorator
Basic Syntax
//kibu:provider [options]Options
| Option | Description | Example |
|---|---|---|
import | Package import path for the provider interface | import=github.com/kibu-sh/kibu/pkg/transport/httpx |
group | Provider group name for aggregation | group=HandlerFactory |
Examples
Simple Provider Function
//kibu:providerfunc NewDatabase(cfg *Config) (*sql.DB, error) { return sql.Open("postgres", cfg.DSN)}Provider with Group
//kibu:provider import=github.com/kibu-sh/kibu/pkg/transport/httpx group=HandlerFactorytype UserServiceController struct { impl UserService}Provider Variable (Wire Set)
//kibu:providervar ServiceWireSet = wire.NewSet( NewUserService, NewOrderService,)Generated Output
kibuwire generates several types of Wire sets:
Package Wire Sets
For each package with providers, a wire set is generated:
var HealthWireSet = wire.NewSet( health.NewService, wire.Struct(new(health.ServiceController), "*"),)Group Sets
Providers with the same group option are aggregated:
var HttpxHandlerFactoryGroup = wire.NewSet( health.ServiceControllerWireSet, users.ServiceControllerWireSet, orders.ServiceControllerWireSet,)Group Provider Functions
Functions that return slices of group interfaces:
func ProvideHttpxHandlerFactoryGroup( healthCtrl *health.ServiceController, usersCtrl *users.ServiceController, ordersCtrl *orders.ServiceController,) []httpx.HandlerFactory { return []httpx.HandlerFactory{ healthCtrl, usersCtrl, ordersCtrl, }}SuperSet
A master wire set combining everything:
var SuperSet = wire.NewSet( HealthWireSet, UsersWireSet, OrdersWireSet, HttpxHandlerFactoryGroup, ProvideHttpxHandlerFactoryGroup,)Common Provider Groups
| Group | Interface | Purpose |
|---|---|---|
HandlerFactory | httpx.HandlerFactory | HTTP route handlers |
WorkerFactory | temporal.WorkerFactory | Temporal workers |
ActivityFactory | temporal.ActivityFactory | Temporal activities |
WorkflowFactory | temporal.WorkflowFactory | Temporal workflows |
Integration with kibugenv2
kibugenv2 automatically adds //kibu:provider decorators to generated controllers:
// Generated by kibugenv2//kibu:provider import=github.com/kibu-sh/kibu/pkg/transport/httpx group=HandlerFactorytype HealthServiceController struct { impl HealthService}This creates a seamless pipeline:
- Define service interfaces with
//kibu:service - Run
kibugenv2to generate controllers with provider annotations - Run
kibuwireto aggregate providers into Wire sets
Example Workflow
Step 1: Define Services
package health
//kibu:servicetype Service interface { //kibu:service:method method=GET Check(ctx context.Context, req CheckRequest) (CheckResponse, error)}Step 2: Generate Plumbing
kibugenv2 ./...This creates health.gen.go with:
//kibu:provider import=github.com/kibu-sh/kibu/pkg/transport/httpx group=HandlerFactorytype ServiceController struct { ... }Step 3: Generate Wire Sets
kibuwire ./...This creates kibuwire/kibuwire.gen.go with organized Wire sets.
Step 4: Use in Main
//go:build wireinject
package main
import ( "github.com/google/wire" "example/kibuwire")
func InitializeApp() (*App, error) { wire.Build( kibuwire.SuperSet, NewApp, ) return nil, nil}Project Structure
After running kibuwire, your project will have:
project/├── src/backend/systems/│ ├── health/│ │ ├── health.go│ │ └── health.gen.go│ └── users/│ ├── users.go│ └── users.gen.go├── kibuwire/│ └── kibuwire.gen.go # Generated Wire sets└── generate.goBest Practices
- Use groups consistently: All HTTP handlers should use
group=HandlerFactory - Don’t edit generated files:
kibuwire/kibuwire.gen.gois regenerated on each run - Run after kibugenv2: Provider annotations come from generated code
- Import the SuperSet: Use
kibuwire.SuperSetin your Wire injector for full coverage
Troubleshooting
Missing providers in SuperSet
Ensure all packages with //kibu:provider annotations are included in the ./... glob pattern.
Import errors
Check that the import= option points to a valid package path with the expected interface.
Wire build failures
Run wire check ./... to diagnose Wire-specific issues after generating with kibuwire.