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