作者 yangfu

Merge remote-tracking branch 'origin/test'

正在显示 1 个修改的文件 包含 19 行增加2 行删除
... ... @@ -4,11 +4,11 @@ import (
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
beeorm "github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/common"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/config"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/orm"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis"
"gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket"
"opp/internal/utils"
... ... @@ -46,7 +46,7 @@ func init() {
beego.AppConfig.String("mysql_db_name"),
)
//log.Info(fmt.Sprintf("init mysql:%v", dataSource))
orm.NewBeeormEngine(config.Mysql{
NewBeeormEngine(config.Mysql{
//AliasName: "default",
DataSource: dataSource,
MaxIdle: 100,
... ... @@ -104,3 +104,20 @@ var FilterBeforeStatic = func(ctx *context.Context) {
ctx.ResponseWriter.Header().Add("Content-Type", "audio/mpeg")
}
}
func NewBeeormEngine(conf config.Mysql) {
aliasName := "default"
if len(conf.AliasName) > 0 {
aliasName = conf.AliasName
}
err := beeorm.RegisterDataBase(aliasName, "mysql", conf.DataSource)
if err != nil {
log.Error(err)
} else {
//log.Debug("open db address:",conf.DataSource)
}
beeorm.SetMaxIdleConns(aliasName, conf.MaxIdle)
beeorm.SetMaxOpenConns(aliasName, conf.MaxOpen)
//orm.DefaultTimeLoc = time.Local
//orm.Debug = true
}
... ...