mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-23 02:40:56 +00:00
feat:Extraction of configuration parameters
This commit is contained in:
+15
-10
@@ -1,10 +1,12 @@
|
||||
// +build sqlite3
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"github.com/jinzhu/gorm"
|
||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go-admin/global/orm"
|
||||
"go-admin/global"
|
||||
"go-admin/tools/config"
|
||||
)
|
||||
|
||||
@@ -12,26 +14,25 @@ type SqLite struct {
|
||||
}
|
||||
|
||||
func (e *SqLite) Setup() {
|
||||
|
||||
var err error
|
||||
var db Database
|
||||
|
||||
db = new(SqLite)
|
||||
orm.Source = db.GetConnect()
|
||||
log.Info(orm.Source)
|
||||
orm.Eloquent, err = db.Open(orm.Driver, orm.Source)
|
||||
global.Source = db.GetConnect()
|
||||
log.Info(global.Source)
|
||||
global.Eloquent, err = db.Open(db.GetDriver(), db.GetConnect())
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("%s connect error %v", orm.Driver, err)
|
||||
log.Fatalf("%s connect error %v", db.GetDriver(), err)
|
||||
} else {
|
||||
log.Printf("%s connect success!", orm.Driver)
|
||||
log.Printf("%s connect success!", db.GetDriver())
|
||||
}
|
||||
|
||||
if orm.Eloquent.Error != nil {
|
||||
log.Fatalf("database error %v", orm.Eloquent.Error)
|
||||
if global.Eloquent.Error != nil {
|
||||
log.Fatalf("database error %v", global.Eloquent.Error)
|
||||
}
|
||||
|
||||
orm.Eloquent.LogMode(true)
|
||||
global.Eloquent.LogMode(true)
|
||||
}
|
||||
|
||||
// 打开数据库连接
|
||||
@@ -42,4 +43,8 @@ func (*SqLite) Open(dbType string, conn string) (db *gorm.DB, err error) {
|
||||
|
||||
func (e *SqLite) GetConnect() string {
|
||||
return config.DatabaseConfig.Source
|
||||
}
|
||||
|
||||
func (e *SqLite) GetDriver() string {
|
||||
return config.DatabaseConfig.Driver
|
||||
}
|
||||
Reference in New Issue
Block a user