cg33 6 лет назад
Родитель
Сommit
9ebef204a7
2 измененных файлов с 4 добавлено и 10 удалено
  1. 1 2
      main.go
  2. 3 8
      models/base.go

+ 1 - 2
main.go

@@ -58,12 +58,11 @@ func startServer() {
 	if err := eng.AddConfigFromJSON("./config.json").
 		AddGenerators(tables.Generators).
 		AddGenerator("external", tables.GetExternalTable).
-		ResolveSqliteConnection(models.SetConn).
 		Use(r); err != nil {
 		panic(err)
 	}
 
-	models.Init()
+	models.Init(eng.SqliteConnection())
 
 	r.Static("/uploads", "./uploads")
 

+ 3 - 8
models/base.go

@@ -6,17 +6,12 @@ import (
 )
 
 var (
-	conn db.Connection
-	orm  *gorm.DB
+	orm *gorm.DB
 	err error
 )
 
-func SetConn(c db.Connection) {
-	conn = c
-}
-
-func Init() {
-	orm, err = gorm.Open("sqlite", conn.GetDB("default"))
+func Init(c db.Connection) {
+	orm, err = gorm.Open("sqlite", c.GetDB("default"))
 
 	if err != nil {
 		panic("initialize orm failed")