fengjiachun/Jupiter

service.Init()和model.Init()初始化位置问题

beancookie opened this issue · 0 comments

Your question

demo项目中如果在启动时将service.Init()放置在model.Init()代码之前,则启动时不会报错,但是调用gorm时则会抛出异常

Your scenes

应用能否正确初始化不应该依赖于代码位置

Your advice

在Repository工厂方法中加入gorm的空值判断用于提示开发者
func NewMysqlImpl(gh *gorm.DB) sys_user.Repository {
if nil == gh {
panic("model Init need before service Init")
}
return &mysqlImpl{
gh: gh,
}
}