Skip to content

CLI

go tool gendi [flags]
FlagDescription
--config stringRoot YAML configuration filerequired
--out stringOutput directory or filerequired
--pkg stringGo package namerequired
--container stringContainer struct namedefault Container
--build-tags stringGo build tagsused for type resolution and emitted as the generated file’s //go:build header
--enable-pass valueEnable a specific compiler passrepeat the flag to enable several
--verboseVerbose loggingprints the path of the file that was written

A successful run is otherwise silent.

Selectable Passes

The stock binary ships two selectable passes; an unknown name is an error raised before generation starts:

--enable-passEffect
slogGives every service tagged slog with a channel attribute its own channel-scoped logger derived from the logger service (see stdlib/README.md)
expose-allMarks every service public, so each one gets a getter. For test containers — it overrides explicit public: false and disables unreachable-service pruning

Registering passes of your own means building your own generator binary — see Building a Custom Generator.

Examples

# Generate into a directory
go tool gendi --config=gendi.yaml --out=./di --pkg=di

# Generate a specific file
go tool gendi --config=gendi.yaml --out=./di/container_gen.go --pkg=di

# Resolve types under a build tag, and emit it as the file's //go:build header
go tool gendi --config=gendi.yaml --out=./di --pkg=di --build-tags=integration

Keeping the command next to the package it writes is what makes regeneration routine:

//go:generate go tool gendi --config=gendi.yaml --out=./di --pkg=di