Code Generation
Weaver ships a CLI tool, cmd/weaver, that generates component registration code. We recommend installing it locally, then using the weaver command for everything.
Installation
go install github.com/jun3372/weaver/cmd/weaver@latestVerify the installation:
weaver versionIf you prefer not to install, go run works as a one-off alternative (every weaver command below can be replaced with go run github.com/jun3372/weaver/cmd/weaver).
Generate Registration Code
# generate for the current package
weaver generate .
# specific packages
weaver generate ./user ./chatThe tool scans target packages for structs embedding weaver.Implements[T] and generates weaver_gen.go in each package, containing the registration info that maps component interfaces to implementations. weaver.Run depends on these registrations to build the component graph.
The generated file carries the ignoreWeaverGen build tag so the tool never re-scans its own output.
With go:generate
Add a //go:generate directive to use go generate directly:
//go:generate weaver generate
package mainVersion
# CLI tool version
weaver versionApplications also support -version (or the environment variable SERVICE_VERSION=true) to print version info:
go run main.go -version