feat:完善入驻信息管理
This commit is contained in:
@ -22,20 +22,39 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func mysql() logic.IEngine {
|
||||
return &logic.Mysql{
|
||||
User: config.SettingInfo.Engine.Mysql.User, Password: config.SettingInfo.Engine.Mysql.Password,
|
||||
Host: config.SettingInfo.Engine.Mysql.Host, Port: config.SettingInfo.Engine.Mysql.Port,
|
||||
DBName: config.SettingInfo.Engine.Mysql.DBName, Parameters: config.SettingInfo.Engine.Mysql.Parameters,
|
||||
type Instance struct {
|
||||
debug bool
|
||||
dbMode string
|
||||
*logic.Mysql
|
||||
*logic.Sqlite
|
||||
}
|
||||
|
||||
type Option func(instance *Instance)
|
||||
|
||||
func WithDebug(debug bool) Option {
|
||||
return func(instance *Instance) {
|
||||
instance.debug = debug
|
||||
}
|
||||
}
|
||||
|
||||
func sqlite() logic.IEngine {
|
||||
return &logic.Sqlite{Path: config.SettingInfo.Engine.Sqlite.Path, Name: config.SettingInfo.Engine.Sqlite.Name}
|
||||
func WithDBMode(dbMode string) Option {
|
||||
return func(instance *Instance) {
|
||||
instance.dbMode = dbMode
|
||||
}
|
||||
}
|
||||
|
||||
func Init() {
|
||||
handle, has := engines[config.SettingInfo.Engine.DBMode]
|
||||
func WithMysqlUser(user string) Option {
|
||||
return func(instance *Instance) {
|
||||
instance.Mysql.User = user
|
||||
}
|
||||
}
|
||||
|
||||
func WithMysql() {
|
||||
|
||||
}
|
||||
|
||||
func (this *Instance) Init() {
|
||||
handle, has := engines[this.dbMode]
|
||||
|
||||
if !has {
|
||||
panic(fmt.Sprintf("Unknown Engine Mode:%d", config.SettingInfo.Engine.DBMode))
|
||||
@ -47,7 +66,7 @@ func Init() {
|
||||
SingularTable: !config.SettingInfo.Engine.Complex,
|
||||
},
|
||||
}
|
||||
if config.SettingInfo.Engine.Debug {
|
||||
if this.debug {
|
||||
option.Logger = logger.New(
|
||||
log.New(os.Stdout, "\r\n", log.LstdFlags),
|
||||
logger.Config{
|
||||
@ -71,9 +90,27 @@ func Init() {
|
||||
orm = db
|
||||
}
|
||||
|
||||
func GetDB() *gorm.DB {
|
||||
if _, err := orm.DB(); err != nil {
|
||||
Init()
|
||||
func NewInstance(option ...Option) *Instance {
|
||||
instance := new(Instance)
|
||||
|
||||
for _, v := range option {
|
||||
v(instance)
|
||||
}
|
||||
return instance
|
||||
}
|
||||
|
||||
func mysql() logic.IEngine {
|
||||
return &logic.Mysql{
|
||||
User: config.SettingInfo.Engine.Mysql.User, Password: config.SettingInfo.Engine.Mysql.Password,
|
||||
Host: config.SettingInfo.Engine.Mysql.Host, Port: config.SettingInfo.Engine.Mysql.Port,
|
||||
DBName: config.SettingInfo.Engine.Mysql.DBName, Parameters: config.SettingInfo.Engine.Mysql.Parameters,
|
||||
}
|
||||
}
|
||||
|
||||
func sqlite() logic.IEngine {
|
||||
return &logic.Sqlite{Path: config.SettingInfo.Engine.Sqlite.Path, Name: config.SettingInfo.Engine.Sqlite.Name}
|
||||
}
|
||||
|
||||
func GetDB() *gorm.DB {
|
||||
return orm
|
||||
}
|
||||
|
Reference in New Issue
Block a user