
kratos-wire
Fix Wire -mod=mod issue in Go workspace mode (go.work) with Kratos projects.
CHINESE README
δΈζθ―΄ζ
Problem
When using Google Wire with Go workspace mode (go.work), go generate ./... fails:
go generate ./...
go: -mod may only be set to readonly or vendor when in workspace mode, but it is set to "mod"
Remove the -mod flag to use the default readonly value,
or set GOWORK=off to disable workspace mode.
xxx/xxx/wire_gen.go:3: running "go": exit status 1
Wire generates code with this directive that conflicts with workspace mode:
//go:generate go run -mod=mod github.com/google/wire/cmd/wire
//go:build !wireinject
// +build !wireinject
Solution
Auto removes the -mod=mod flag from Wire-generated files, making them workspace-compatible:
//go:generate go run github.com/google/wire/cmd/wire
Wire Status (2025)
- Latest version: v0.7.0 (August 22, 2025)
- Repo: Archived, read-access-mode (August 25, 2025)
- Workspace issue: NOT fixed (PR #410 remains open)
- This package remains needed as Wire won't receive more updates
Installation
go install github.com/yylego/kratos-wire/cmd/wirekratos@latest
Usage
Auto mode (Kratos projects)
wirekratos -framework=kratos
Auto detects cmd/PROJECT_NAME/wire_gen.go in Kratos projects.
Relative path mode
wirekratos -name=cmd/myproject/wire_gen.go
Absolute path mode
wirekratos -path=/absolute/path/to/wire_gen.go
Debug mode
wirekratos -framework=kratos -debug
Demo Projects
Complete demo projects showing integration in production Kratos applications:
kratos-wire-demos - Full-featured Kratos applications with Wire integration
How It Works
- Locates
wire_gen.go file
- Checks Wire-generated code signature
- Finds the
//go:generate directive (line 3)
- Removes
-mod=mod flag if present
- Keeps everything else unchanged
π License
MIT License - see LICENSE.
Contributions are welcome! Report bugs, suggest features, and contribute code:
- π Mistake reports? Open an issue on GitHub with reproduction steps
- π‘ Fresh ideas? Create an issue to discuss
- π Documentation confusing? Report it so we can improve
- π Need new features? Share the use cases to help us understand requirements
- β‘ Performance issue? Help us optimize via reporting slow operations
- π§ Configuration problem? Ask questions about complex setups
- π’ Follow project progress? Watch the repo to get new releases and features
- π Success stories? Share how this package improved the workflow
- π¬ Feedback? We welcome suggestions and comments
π§ Development
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage UI).
- Clone: Clone the forked project (
git clone https://github.com/yourname/kratos-wire.git).
- Navigate: Navigate to the cloned project (
cd kratos-wire)
- Branch: Create a feature branch (
git checkout -b feature/xxx).
- Code: Implement the changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...) and follow Go code style conventions
- Documentation: Update documentation to support client-facing changes and use significant commit messages
- Stage: Stage changes (
git add .)
- Commit: Commit changes (
git commit -m "Add feature xxx") ensuring backward compatible code
- Push: Push to the branch (
git push origin feature/xxx).
- PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.
Please ensure tests pass and include relevant documentation updates.
π Support
Welcome to contribute to this project via submitting merge requests and reporting issues.
Project Support:
- β Give GitHub stars if this project helps
- π€ Share with teammates and (golang) programming friends
- π Write tech blogs about development tools and workflows - we provide content writing support
- π Join the ecosystem - committed to supporting open source and the (golang) development scene
Have Fun Coding with this package! πππ
GitHub Stars
