Skip to content

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

Open
@beancookie

Description

@beancookie

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,
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions