12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package models
- import (
- "fmt"
- "log"
- "time"
- "../pkg/setting"
- "../routers/restful"
- "github.com/astaxie/beego/logs"
- "github.com/xormplus/xorm"
- )
- var Engine *xorm.Engine
- var SqlServerEngine *xorm.Engine
- func Setup() {
- var err error
- // restful 接口的 数据库初始化
- if err := restful.SQLInit("mysql", fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=True&loc=Local",
- setting.DatabaseSetting.User,
- setting.DatabaseSetting.Password,
- setting.DatabaseSetting.Host,
- setting.DatabaseSetting.Name), 1000, 10, setting.DatabaseSetting.ShowXormlog); err != nil {
- log.Fatal(err.Error())
- fmt.Println("dbs 数据库初始化失败 ")
- }
- Engine = restful.Engine
- if err != nil {
- log.Fatalf("models.Setup err: %v", err)
- }
- Engine.SetConnMaxLifetime(time.Second * 30)
- Engine.ShowSQL(true)
- if err = Engine.Ping(); err != nil {
- logs.Error(err)
- panic(err)
- }
- }
- func SetupSqlserver() {
- // if setting.SQlserverSetting.Host != "" {
- // var err error
- // // restful 接口的 数据库初始化
- // if err := restful.SQLInit("odbc", setting.SQlserverSetting.Host, 1000, 10, setting.DatabaseSetting.ShowXormlog); err != nil {
- // log.Fatal(err.Error())
- // fmt.Println("dbs 数据库初始化失败 ")
- // }
- // SqlServerEngine = restful.Engine
- // if err != nil {
- // log.Fatalf("models.Setup err: %v", err)
- // }
- // SqlServerEngine.SetConnMaxLifetime(time.Second * 30)
- // SqlServerEngine.ShowSQL(true)
- // if err = SqlServerEngine.Ping(); err != nil {
- // logs.Error(err)
- // panic(err)
- // }
- // }
- }
|