Repository navigation
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