Fix Wire -mod=mod issue in Go workspace mode (go.work) with Kratos projects.
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 !wireinjectAuto removes the -mod=mod flag from Wire-generated files, making them workspace-compatible:
//go:generate go run github.com/google/wire/cmd/wire- 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
go install github.com/yylego/kratos-wire/cmd/wirekratos@latestwirekratos -framework=kratosAuto detects cmd/PROJECT_NAME/wire_gen.go in Kratos projects.
wirekratos -name=cmd/myproject/wire_gen.gowirekratos -path=/absolute/path/to/wire_gen.gowirekratos -framework=kratos -debugComplete demo projects showing integration in production Kratos applications:
kratos-wire-demos - Full-featured Kratos applications with Wire integration
- demo1kratos - Basic Kratos project setup
- demo2kratos - Advanced Kratos project with workspace
- Locates
wire_gen.gofile - Checks Wire-generated code signature
- Finds the
//go:generatedirective (line 3) - Removes
-mod=modflag if present - Keeps everything else unchanged
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
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.
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! 🎉🎉🎉