ziwen hai 1 ano
pai
achega
e750565f37
Modificáronse 1 ficheiros con 38 adicións e 25 borrados
  1. 38 25
      models/db.go

+ 38 - 25
models/db.go

@@ -19,40 +19,53 @@ func init() {
 	db, _ := orm.GetDB("default")
 	db.SetConnMaxLifetime(10 * time.Minute)
 
-	_ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
-	orm.SetMaxIdleConns("rddp", 50)
-	orm.SetMaxOpenConns("rddp", 100)
+	if utils.MYSQL_URL_RDDP != ""{
+		_ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
+		orm.SetMaxIdleConns("rddp", 50)
+		orm.SetMaxOpenConns("rddp", 100)
 
-	report_db, _ := orm.GetDB("rddp")
-	report_db.SetConnMaxLifetime(10 * time.Minute)
+		report_db, _ := orm.GetDB("rddp")
+		report_db.SetConnMaxLifetime(10 * time.Minute)
+	}
 
-	_ = orm.RegisterDataBase("edb", "mysql", utils.MYSQL_URL_EDB)
-	orm.SetMaxIdleConns("edb", 50)
-	orm.SetMaxOpenConns("edb", 100)
+	if utils.MYSQL_URL_EDB != ""{
+		_ = orm.RegisterDataBase("edb", "mysql", utils.MYSQL_URL_EDB)
+		orm.SetMaxIdleConns("edb", 50)
+		orm.SetMaxOpenConns("edb", 100)
 
-	edb_db, _ := orm.GetDB("edb")
-	edb_db.SetConnMaxLifetime(10 * time.Minute)
+		edb_db, _ := orm.GetDB("edb")
+		edb_db.SetConnMaxLifetime(10 * time.Minute)
+	}
 
-	_ = orm.RegisterDataBase("data", "mysql", utils.MYSQL_URL_DATA)
-	orm.SetMaxIdleConns("data", 50)
-	orm.SetMaxOpenConns("data", 100)
 
-	data_db, _ := orm.GetDB("data")
-	data_db.SetConnMaxLifetime(10 * time.Minute)
+	if utils.MYSQL_URL_DATA != ""{
+		_ = orm.RegisterDataBase("data", "mysql", utils.MYSQL_URL_DATA)
+		orm.SetMaxIdleConns("data", 50)
+		orm.SetMaxOpenConns("data", 100)
 
-	_ = orm.RegisterDataBase("gl", "mysql", utils.MYSQL_URL_GL)
-	orm.SetMaxIdleConns("gl", 50)
-	orm.SetMaxOpenConns("gl", 100)
+		data_db, _ := orm.GetDB("data")
+		data_db.SetConnMaxLifetime(10 * time.Minute)
 
-	gl, _ := orm.GetDB("gl")
-	gl.SetConnMaxLifetime(10 * time.Minute)
+	}
 
-	_ = orm.RegisterDataBase("eta", "mysql", utils.MYSQL_URL_ETA)
-	orm.SetMaxIdleConns("eta", 50)
-	orm.SetMaxOpenConns("eta", 100)
+	if utils.MYSQL_URL_GL != ""{
+		_ = orm.RegisterDataBase("gl", "mysql", utils.MYSQL_URL_GL)
+		orm.SetMaxIdleConns("gl", 50)
+		orm.SetMaxOpenConns("gl", 100)
+
+		gl, _ := orm.GetDB("gl")
+		gl.SetConnMaxLifetime(10 * time.Minute)
+	}
+
+	if utils.MYSQL_URL_ETA != ""{
+		_ = orm.RegisterDataBase("eta", "mysql", utils.MYSQL_URL_ETA)
+		orm.SetMaxIdleConns("eta", 50)
+		orm.SetMaxOpenConns("eta", 100)
+
+		etaDb, _ := orm.GetDB("eta")
+		etaDb.SetConnMaxLifetime(10 * time.Minute)
+	}
 
-	etaDb, _ := orm.GetDB("eta")
-	etaDb.SetConnMaxLifetime(10 * time.Minute)
 
 	orm.Debug = true
 	orm.DebugLog = orm.NewLog(utils.Binlog)