mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
panic output detail info
This commit is contained in:
parent
72b09864ce
commit
0ea48af892
@ -2,6 +2,7 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"Open_IM/pkg/common/config"
|
"Open_IM/pkg/common/config"
|
||||||
|
"Open_IM/pkg/common/log"
|
||||||
"github.com/garyburd/redigo/redis"
|
"github.com/garyburd/redigo/redis"
|
||||||
"gopkg.in/mgo.v2"
|
"gopkg.in/mgo.v2"
|
||||||
"time"
|
"time"
|
||||||
@ -20,6 +21,8 @@ func key(dbAddress, dbName string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
var mgoSession *mgo.Session
|
||||||
|
var err1 error
|
||||||
//mysql init
|
//mysql init
|
||||||
initMysqlDB()
|
initMysqlDB()
|
||||||
// mongo init
|
// mongo init
|
||||||
@ -35,7 +38,14 @@ func init() {
|
|||||||
}
|
}
|
||||||
mgoSession, err := mgo.DialWithInfo(mgoDailInfo)
|
mgoSession, err := mgo.DialWithInfo(mgoDailInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err.Error())
|
log.NewError("mgo init err", err.Error(), mgoDailInfo)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
time.Sleep(time.Duration(30) * time.Second)
|
||||||
|
mgoSession, err1 = mgo.DialWithInfo(mgoDailInfo)
|
||||||
|
if err1 != nil {
|
||||||
|
panic(err1.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
DB.mgoSession = mgoSession
|
DB.mgoSession = mgoSession
|
||||||
DB.mgoSession.SetMode(mgo.Monotonic, true)
|
DB.mgoSession.SetMode(mgo.Monotonic, true)
|
||||||
|
@ -19,13 +19,19 @@ func initMysqlDB() {
|
|||||||
//When there is no open IM database, connect to the mysql built-in database to create openIM database
|
//When there is no open IM database, connect to the mysql built-in database to create openIM database
|
||||||
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local",
|
||||||
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql")
|
config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql")
|
||||||
|
var db *gorm.DB
|
||||||
|
var err1 error
|
||||||
db, err := gorm.Open("mysql", dsn)
|
db, err := gorm.Open("mysql", dsn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("", "", dsn)
|
log.Error("", "", dsn)
|
||||||
panic(err.Error())
|
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
time.Sleep(time.Duration(30) * time.Second)
|
||||||
|
db, err1 = gorm.Open("mysql", dsn)
|
||||||
|
if err1 != nil {
|
||||||
|
panic(err1.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
//Check the database and table during initialization
|
//Check the database and table during initialization
|
||||||
sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", config.Config.Mysql.DBDatabaseName)
|
sql := fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s ;", config.Config.Mysql.DBDatabaseName)
|
||||||
err = db.Exec(sql).Error
|
err = db.Exec(sql).Error
|
||||||
|
Loading…
x
Reference in New Issue
Block a user