go.mod 版本管理与依赖注入模式,构建可测试的 Go 应用。
go mod init example.com/myapp go mod tidy go build ./...
Go 社区倾向手动 DI,通过构造函数注入依赖,避免反射框架。
type Service struct { repo Repository } func NewService(r Repository) *Service { return &Service{repo: r} }