go项目脚手架
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sorbet/internal/init.go

54 lines
1.2 KiB

package internal
import (
"errors"
"sorbet/internal/entities"
"sorbet/internal/repositories"
"sorbet/pkg/db"
"sorbet/pkg/env"
"sorbet/pkg/ioc"
"sorbet/pkg/log"
)
func Init() error {
ioc.Bind(db.DB()) // 注入数据库操作
ioc.Bind(log.Default()) // 注入日志操作
repositories.Init() // 注入数据仓库操作
// 同步数据库结构
if err := syncEntities(); err != nil {
if !errors.Is(err, db.ErrNoCodeFirst) {
return err
}
if !env.IsEnv("prod") {
log.Error("同步数据表结构需要开启 [DB_CODE_FIRST],在生产模式下请务必关闭。")
}
}
return nil
}
func syncEntities() error {
return db.Sync(
&entities.Company{},
&entities.CompanyDepartment{},
&entities.CompanyStaff{},
&entities.Config{},
&entities.ConfigGroup{},
&entities.Feature{},
&entities.FeatureCategory{},
&entities.FeatureConfig{},
&entities.FeatureContent{},
&entities.FeatureContentChapter{},
&entities.FeatureContentDetail{},
&entities.Resource{},
&entities.ResourceCategory{},
&entities.SystemLog{},
&entities.SystemMenu{},
&entities.SystemPermission{},
&entities.SystemRole{},
&entities.SystemRolePower{},
&entities.SystemUser{},
)
}