Explorar o código

连接高斯数据库

xyxie hai 2 meses
pai
achega
4cd20b3d91
Modificáronse 4 ficheiros con 16 adicións e 15 borrados
  1. 1 1
      go.mod
  2. 0 2
      go.sum
  3. 9 9
      models/db.go
  4. 6 3
      utils/config.go

+ 1 - 1
go.mod

@@ -11,10 +11,10 @@ require (
 	github.com/go-sql-driver/mysql v1.7.0
 	github.com/gorilla/websocket v1.5.1
 	github.com/kgiannakakis/mp3duration v0.0.0-20191013070830-d834f8d5ed53
+	github.com/lib/pq v1.10.5
 	github.com/olivere/elastic/v7 v7.0.32
 	github.com/rdlucklib/rdluck_tools v1.0.3
 	github.com/shopspring/decimal v1.3.1
-	github.com/tealeg/xlsx v1.0.5
 	golang.org/x/net v0.21.0
 	gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df
 )

+ 0 - 2
go.sum

@@ -191,8 +191,6 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
 github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
 github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
 github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
-github.com/tealeg/xlsx v1.0.5 h1:+f8oFmvY8Gw1iUXzPk+kz+4GpbDZPK1FhPiQRd+ypgE=
-github.com/tealeg/xlsx v1.0.5/go.mod h1:btRS8dz54TDnvKNosuAqxrM1QgN1udgk9O34bDCnORM=
 github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
 github.com/wendal/errors v0.0.0-20130201093226-f66c77a7882b/go.mod h1:Q12BUT7DqIlHRmgv3RskH+UCM/4eqVMgI0EMmlSpAXc=
 github.com/ylywyn/jpush-api-go-client v0.0.0-20190906031852-8c4466c6e369/go.mod h1:Nv7wKD2/bCdKUFNKcJRa99a+1+aSLlCRJFriFYdjz/I=

+ 9 - 9
models/db.go

@@ -8,14 +8,14 @@ import (
 	"eta/eta_task/utils"
 	"time"
 
-	_ "github.com/go-sql-driver/mysql"
-
 	"github.com/beego/beego/v2/client/orm"
+	_ "github.com/go-sql-driver/mysql"
+	_ "github.com/lib/pq"
 )
 
 func init() {
 
-	_ = orm.RegisterDataBase("default", "mysql", utils.MYSQL_URL)
+	_ = orm.RegisterDataBase("default", utils.DBDRIVER_NAME, utils.MYSQL_URL)
 	orm.SetMaxIdleConns("default", 50)
 	orm.SetMaxOpenConns("default", 100)
 
@@ -23,7 +23,7 @@ func init() {
 	db.SetConnMaxLifetime(10 * time.Minute)
 
 	if utils.MYSQL_URL_RDDP != "" {
-		_ = orm.RegisterDataBase("rddp", "mysql", utils.MYSQL_URL_RDDP)
+		_ = orm.RegisterDataBase("rddp", utils.DBDRIVER_NAME, utils.MYSQL_URL_RDDP)
 		orm.SetMaxIdleConns("rddp", 50)
 		orm.SetMaxOpenConns("rddp", 100)
 
@@ -32,7 +32,7 @@ func init() {
 	}
 
 	if utils.MYSQL_URL_EDB != "" {
-		_ = orm.RegisterDataBase("edb", "mysql", utils.MYSQL_URL_EDB)
+		_ = orm.RegisterDataBase("edb", utils.DBDRIVER_NAME, utils.MYSQL_URL_EDB)
 		orm.SetMaxIdleConns("edb", 50)
 		orm.SetMaxOpenConns("edb", 100)
 
@@ -41,7 +41,7 @@ func init() {
 	}
 
 	if utils.MYSQL_URL_DATA != "" {
-		_ = orm.RegisterDataBase("data", "mysql", utils.MYSQL_URL_DATA)
+		_ = orm.RegisterDataBase("data", utils.DBDRIVER_NAME, utils.MYSQL_URL_DATA)
 		orm.SetMaxIdleConns("data", 50)
 		orm.SetMaxOpenConns("data", 100)
 
@@ -51,7 +51,7 @@ func init() {
 	}
 
 	if utils.MYSQL_URL_GL != "" {
-		_ = orm.RegisterDataBase("gl", "mysql", utils.MYSQL_URL_GL)
+		_ = orm.RegisterDataBase("gl", utils.DBDRIVER_NAME, utils.MYSQL_URL_GL)
 		orm.SetMaxIdleConns("gl", 50)
 		orm.SetMaxOpenConns("gl", 100)
 
@@ -60,7 +60,7 @@ func init() {
 	}
 
 	if utils.MYSQL_URL_ETA != "" {
-		_ = orm.RegisterDataBase("eta", "mysql", utils.MYSQL_URL_ETA)
+		_ = orm.RegisterDataBase("eta", utils.DBDRIVER_NAME, utils.MYSQL_URL_ETA)
 		orm.SetMaxIdleConns("eta", 50)
 		orm.SetMaxOpenConns("eta", 100)
 
@@ -69,7 +69,7 @@ func init() {
 	}
 	// 用户主库
 	if utils.MYSQL_WEEKLY_URL != `` && (utils.BusinessCode == utils.BusinessCodeRelease || utils.BusinessCode == utils.BusinessCodeSandbox || utils.BusinessCode == utils.BusinessCodeDebug) {
-		_ = orm.RegisterDataBase("weekly", "mysql", utils.MYSQL_WEEKLY_URL)
+		_ = orm.RegisterDataBase("weekly", utils.DBDRIVER_NAME, utils.MYSQL_WEEKLY_URL)
 		orm.SetMaxIdleConns("weekly", 50)
 		orm.SetMaxOpenConns("weekly", 100)
 

+ 6 - 3
utils/config.go

@@ -17,8 +17,8 @@ var (
 	MYSQL_URL_GL     string
 	MYSQL_URL_ETA    string
 	MYSQL_WEEKLY_URL string //用户主库
-
-	REDIS_CACHE string //缓存地址
+	DBDRIVER_NAME    string //数据库驱动
+	REDIS_CACHE      string //缓存地址
 	//Rc          *cache.Cache //redis缓存
 	Re error       //redis错误
 	Rc RedisClient //redis缓存
@@ -190,7 +190,10 @@ func init() {
 	beego.Info(RunMode + " 模式")
 	MYSQL_URL = config["mysql_url"]
 	MYSQL_URL_RDDP = config["mysql_url_rddp"]
-
+	DBDRIVER_NAME = config["db_driver_name"]
+	if DBDRIVER_NAME == "" {
+		DBDRIVER_NAME = "mysql"
+	}
 	MYSQL_URL_EDB = config["mysql_url_edb"]
 	MYSQL_URL_DATA = config["mysql_url_data"]
 	MYSQL_URL_GL = config["mysql_url_gl"]