Skip to content

v0.1.0

Choose a tag to compare

@github-actions github-actions released this 17 Nov 15:14
· 9 commits to main since this release

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.Bind from github.com/withnic/knit, in files tagged //go:build knitinject. Code is generated into knit_gen.go. No dependency on google/wire.
  • wire mode (-mode=wire): a drop-in replacement for the wire command. It reads existing wire.go files and writes the same wire_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 mode

Prebuilt 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/knit

Not 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 を参照してください。