Repository navigation
Releases
v0.4.0
English | 日本語
This release changes the order in which generated code calls providers, so that it matches google/wire and no longer depends on function names.
Breaking change
- Providers whose order is not fixed by their dependencies used to be called in alphabetical order of their package path and function name, so renaming a constructor could change the call order and the cleanup order.
- knit now uses the same order as google/wire: starting from the injector's result, each provider's dependencies are built first, in the order of its parameters. To change the order of independent providers, reorder the parameters of the constructor that uses them.
- With
-mode=wire, the call order now matches what google/wire generates.
Regenerated code may call independent providers in a different order, run their cleanups in a different order and number variables (v1, v2, ...) differently. Regenerate with knit gen and review the diff, especially if your providers have side effects or cleanups that depend on each other.
Install
Requires Go 1.26 or later (only for go install / importing the marker package).
go install github.com/withnic/knit/cmd/knit@v0.4.0 # or: go get -tool github.com/withnic/knit/cmd/knit@v0.4.0
go get github.com/withnic/knit@v0.4.0 # marker package for native modePrebuilt binaries for Linux, macOS and Windows (amd64 / arm64) are attached below. Verify a download with checksums.txt, or check its build provenance with:
gh attestation verify knit_0.4.0_linux_amd64.tar.gz -R withnic/knitFull changes: v0.3.0...v0.4.0
日本語
このリリースでは、生成コードがプロバイダを呼び出す順序を google/wire と同じにし、関数名に左右されないようにしました。
破壊的変更
- これまで、依存関係で順番が決まらないプロバイダは、パッケージパスと関数名のアルファベット順に呼び出していました。そのため、コンストラクタの名前を変えると呼び出し順や終了処理の順序が変わることがありました。
- google/wire と同じ順に呼び出すようにしました。Injector の戻り値から始めて、各プロバイダの依存を引数の順に先に作ります。依存関係のないプロバイダの順序を変えたいときは、それを使うコンストラクタの引数の順を入れ替えてください。
-mode=wireの呼び出し順が、google/wire の生成結果と一致するようになりました。
再生成すると、依存関係のないプロバイダの呼び出し順、終了処理の順序、変数の番号(v1、v2 …)が変わることがあります。knit gen で再生成して差分を確認してください。特に、副作用のあるプロバイダや、互いに依存する終了処理がある場合はご注意ください。
インストール
Go 1.26 以上が必要です(go install とマーカーパッケージの import の場合のみ)。
go install github.com/withnic/knit/cmd/knit@v0.4.0 # または: go get -tool github.com/withnic/knit/cmd/knit@v0.4.0
go get github.com/withnic/knit@v0.4.0 # knit モード用のマーカーパッケージLinux・macOS・Windows(amd64 / arm64)向けのビルド済みバイナリを下に添付しています。ダウンロードしたファイルは checksums.txt で確認できます。ビルドの証明は次のコマンドで検証できます。
gh attestation verify knit_0.4.0_linux_amd64.tar.gz -R withnic/knitすべての変更: v0.3.0...v0.4.0
v0.3.0
English | 日本語
This release removes the dependency graph output, so knit gen now writes only the generated Go files.
Breaking change
knit genno longer writes.knit/di-graph.json.- The
-graph-outflag has been removed. Commands that pass it now fail with a usage error (exit code2), so remove it from your scripts and CI. - You can delete an existing
.knit/directory, along with its.gitignoreentry.
If you need the graph, stay on v0.2.0.
Generated code is unchanged, so you do not need to regenerate it.
Install
Requires Go 1.26 or later (only for go install / importing the marker package).
go install github.com/withnic/knit/cmd/knit@v0.3.0 # or: go get -tool github.com/withnic/knit/cmd/knit@v0.3.0
go get github.com/withnic/knit@v0.3.0 # marker package for native modePrebuilt binaries for Linux, macOS and Windows (amd64 / arm64) are attached below. Verify a download with checksums.txt, or check its build provenance with:
gh attestation verify knit_0.3.0_linux_amd64.tar.gz -R withnic/knitFull changes: v0.2.0...v0.3.0
日本語
このリリースでは依存グラフの出力を削除しました。knit gen が書き出すのは、生成した Go ファイルだけになります。
破壊的変更
knit genは.knit/di-graph.jsonを出力しなくなりました。-graph-outフラグを削除しました。指定すると使い方エラー(終了コード2)になるので、スクリプトや CI から外してください。- 既存の
.knit/ディレクトリと、.gitignoreの該当行は削除できます。
グラフが必要な場合は、v0.2.0 を使い続けてください。
生成コードは変わらないので、再生成は不要です。
インストール
Go 1.26 以上が必要です(go install とマーカーパッケージの import の場合のみ)。
go install github.com/withnic/knit/cmd/knit@v0.3.0 # または: go get -tool github.com/withnic/knit/cmd/knit@v0.3.0
go get github.com/withnic/knit@v0.3.0 # knit モード用のマーカーパッケージLinux・macOS・Windows(amd64 / arm64)向けのビルド済みバイナリを下に添付しています。ダウンロードしたファイルは checksums.txt で確認できます。ビルドの証明は次のコマンドで検証できます。
gh attestation verify knit_0.3.0_linux_amd64.tar.gz -R withnic/knitすべての変更: v0.2.0...v0.3.0
v0.2.0
English | 日本語
This release makes knit gen catch code that could not build, makes generated cleanups more robust, and shows the full dependency path for more errors.
Before you upgrade
- Regenerate your code. Generated code that uses cleanups has a new form, so
knit genproduces a diff. The cleanup order is still LIFO. knit gennow rejects some projects that it used to accept. Most of these previously failed later, atgo build.
Now reported by knit gen |
What to do |
|---|---|
An injector file without the knitinject / wireinject build tag |
Add the build tag |
| A provider declared in a file with the inject build tag | Move it to a file without the tag |
| An unexported provider from another package | Export it |
| An output file that is not marked as generated | Move it, or choose another name with -out |
| A generated file in a package that no longer declares injectors | Delete the file |
wire mode: unlike wire, knit does not copy other declarations from wire.go into wire_gen.go. Move providers, and anything your regular code uses, to a file without the wireinject tag. The v0.1.0 notes called wire mode a drop-in replacement that writes the same wire_gen.go; that was not accurate.
Fixed
- Type aliases inside pointers, slices, maps and type arguments are now treated as their target types, so
*Aliasand*Targetmatch. - A nil cleanup function is skipped instead of causing a panic.
- A cleanup that panics no longer prevents the remaining cleanups from running. The panic still propagates afterwards.
- Generated code compiles even when the package declares its own
lenorappend.
Improved error messages
Duplicate providers and Bind type mismatches now show the path from the injector's result type, and a Bind mismatch explains the cause:
failed to resolve provider for injector 'InitializeService':
*app.Service -> app.Store -> app.SQLStore (invalid Bind: /path/to/wire.go:8:44: app.SQLStore does not implement app.Store, but *app.SQLStore does; use new(*app.SQLStore))
When two types in a path have the same short name, they are shown with their full import paths. Messages no longer use wire-specific wording in knit mode.
Install
Requires Go 1.26 or later (only for go install / importing the marker package).
go install github.com/withnic/knit/cmd/knit@v0.2.0 # or: go get -tool github.com/withnic/knit/cmd/knit@v0.2.0
go get github.com/withnic/knit@v0.2.0 # marker package for native modePrebuilt binaries for Linux, macOS and Windows (amd64 / arm64) are attached below. Verify a download with checksums.txt, or check its build provenance with:
gh attestation verify knit_0.2.0_linux_amd64.tar.gz -R withnic/knitFull changes: v0.1.0...v0.2.0
日本語
このリリースでは、ビルドできないコードを knit gen の時点で検出し、生成されるクリーンアップ処理を堅牢にして、より多くのエラーで依存のつながりを表示するようにしました。
アップグレードの前に
- コードを再生成してください。 クリーンアップを使う生成コードの形が変わったため、
knit genを実行すると差分が出ます。実行順はこれまでどおり逆順(LIFO)です。 - これまで受け付けていた一部のプロジェクトを、
knit genがエラーにします。 その多くは、以前は後のgo buildで失敗していたものです。
knit gen が報告する内容 |
対応 |
|---|---|
knitinject / wireinject のビルドタグがない Injector ファイル |
ビルドタグを追加する |
| Injector 用ビルドタグ付きファイルで宣言されたプロバイダ | タグのないファイルへ移す |
| 別パッケージの非公開プロバイダ | 公開する |
| 生成コードの印がない出力先ファイル | ファイルを移すか、-out で別の名前を指定する |
| Injector がなくなったパッケージに残った生成ファイル | ファイルを削除する |
wire モード: wire と異なり、knit は wire.go 内のその他の宣言を wire_gen.go にコピーしません。プロバイダや通常のコードから使うものは、wireinject タグのないファイルへ移してください。v0.1.0 のリリースノートでは、wire モードを「同じ wire_gen.go を生成するドロップイン代替」と説明していましたが、正確ではありませんでした。
修正
- ポインタ、スライス、map、型引数の中の型エイリアスを元の型として扱うようにしました。
*Aliasと*Targetが一致します。 - nil のクリーンアップ関数で panic せず、飛ばすようにしました。
- クリーンアップが panic しても、残りのクリーンアップを実行するようにしました。panic はそのあと呼び出し元へ伝わります。
- パッケージが独自の
lenやappendを宣言していても、生成コードがコンパイルできるようにしました。
エラーメッセージの改善
プロバイダの重複と Bind の型不一致で、Injector の戻り値の型からの経路を表示するようにしました。Bind の型不一致では原因も表示します。
failed to resolve provider for injector 'InitializeService':
*app.Service -> app.Store -> app.SQLStore (invalid Bind: /path/to/wire.go:8:44: app.SQLStore does not implement app.Store, but *app.SQLStore does; use new(*app.SQLStore))
経路の中に短い名前が同じ型がある場合は、完全な import パスで表示します。knit モードのメッセージに wire 固有の表記は出なくなりました。
インストール
Go 1.26 以上が必要です(go install とマーカーパッケージの import の場合のみ)。
go install github.com/withnic/knit/cmd/knit@v0.2.0 # または: go get -tool github.com/withnic/knit/cmd/knit@v0.2.0
go get github.com/withnic/knit@v0.2.0 # knit モード用のマーカーパッケージLinux・macOS・Windows(amd64 / arm64)向けのビルド済みバイナリを下に添付しています。ダウンロードしたファイルは checksums.txt で確認できます。ビルドの証明は次のコマンドで検証できます。
gh attestation verify knit_0.2.0_linux_amd64.tar.gz -R withnic/knitすべての変更: v0.1.0...v0.2.0
v0.1.0
English | 日本語
The first release of knit, a lightweight compile-time dependency injection code generator for Go, in the style of google/wire (now archived).
Highlights
- Native mode (default): declare injectors with
knit.Build/knit.NewSet/knit.Bindfromgithub.com/withnic/knit, in files tagged//go:build knitinject. Code is generated intoknit_gen.go. No dependency on google/wire. - wire mode (
-mode=wire): a drop-in replacement for thewirecommand. It reads existingwire.gofiles and writes the samewire_gen.go. - Providers returning
(T),(T, error),(T, func())or(T, func(), error), provider sets (nested, across packages), interface bindings and injector parameters. - Cleanup on failure: if a provider fails, the cleanups of everything built so far run in reverse order (LIFO).
- Deterministic output and clear errors that show the full dependency chain.
- Dependency graph: each run also writes
.knit/di-graph.json, describing what every injector depends on.
Install
Requires Go 1.26 or later (only for go install / importing the marker package).
go install github.com/withnic/knit/cmd/knit@v0.1.0 # or: go get -tool github.com/withnic/knit/cmd/knit@v0.1.0
go get github.com/withnic/knit@v0.1.0 # marker package for native modePrebuilt binaries for Linux, macOS and Windows (amd64 / arm64) are attached below. Verify a download with checksums.txt, or check its build provenance with:
gh attestation verify knit_0.1.0_linux_amd64.tar.gz -R withnic/knitNot supported
wire.Struct, wire.Value, wire.InterfaceValue, wire.FieldsOf, and variadic, method or generic providers are intentionally out of scope; each has a simple alternative.
See the README for the quick start, migration from google/wire and the command reference.
日本語
knit の最初のリリースです。knit は、google/wire(アーカイブ済み)と同じスタイルで使える、Go 向けの軽量なコンパイル時 DI コードジェネレータです。
主な機能
- knit モード(デフォルト):
github.com/withnic/knitのknit.Build/knit.NewSet/knit.Bindを使い、//go:build knitinject付きのファイルで Injector を宣言します。コードはknit_gen.goに生成されます。google/wire への依存は不要です。 - wire モード(
-mode=wire):wireコマンドのドロップイン代替です。既存のwire.goを読み、同じwire_gen.goを生成します。 - プロバイダ:
(T)、(T, error)、(T, func())、(T, func(), error)を返す関数に対応します。プロバイダセット(ネストや別パッケージにも対応)、インターフェースのバインド、Injector の引数も使えます。 - 失敗時のクリーンアップ: プロバイダが失敗したときは、それまでに作ったもののクリーンアップを逆順(LIFO)に実行します。
- 決定論的な出力と、依存のつながりをすべて表示する分かりやすいエラー。
- 依存グラフ: 実行のたびに
.knit/di-graph.jsonも出力し、各 Injector が何に依存しているかを記録します。
インストール
Go 1.26 以上が必要です(go install とマーカーパッケージの import の場合のみ)。
go install github.com/withnic/knit/cmd/knit@v0.1.0 # または: go get -tool github.com/withnic/knit/cmd/knit@v0.1.0
go get github.com/withnic/knit@v0.1.0 # knit モード用のマーカーパッケージLinux・macOS・Windows(amd64 / arm64)向けのビルド済みバイナリを下に添付しています。ダウンロードしたファイルは checksums.txt で確認できます。ビルドの証明は次のコマンドで検証できます。
gh attestation verify knit_0.1.0_linux_amd64.tar.gz -R withnic/knitサポートしない機能
wire.Struct、wire.Value、wire.InterfaceValue、wire.FieldsOf、可変長引数・メソッド・ジェネリックのプロバイダは、意図的に対象外にしています。どれも簡単な代わりの書き方があります。
クイックスタート、google/wire からの移行方法、コマンドの説明は README を参照してください。