正在显示
1 个修改的文件
包含
19 行增加
和
2 行删除
@@ -4,11 +4,11 @@ import ( | @@ -4,11 +4,11 @@ import ( | ||
4 | "fmt" | 4 | "fmt" |
5 | "github.com/astaxie/beego" | 5 | "github.com/astaxie/beego" |
6 | "github.com/astaxie/beego/context" | 6 | "github.com/astaxie/beego/context" |
7 | + beeorm "github.com/astaxie/beego/orm" | ||
7 | _ "github.com/go-sql-driver/mysql" | 8 | _ "github.com/go-sql-driver/mysql" |
8 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" | 9 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/common" |
9 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/config" | 10 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/config" |
10 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" | 11 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/log" |
11 | - "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/orm" | ||
12 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis" | 12 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/redis" |
13 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" | 13 | "gitlab.fjmaimaimai.com/mmm-go/gocomm/pkg/websocket" |
14 | "opp/internal/utils" | 14 | "opp/internal/utils" |
@@ -46,7 +46,7 @@ func init() { | @@ -46,7 +46,7 @@ func init() { | ||
46 | beego.AppConfig.String("mysql_db_name"), | 46 | beego.AppConfig.String("mysql_db_name"), |
47 | ) | 47 | ) |
48 | //log.Info(fmt.Sprintf("init mysql:%v", dataSource)) | 48 | //log.Info(fmt.Sprintf("init mysql:%v", dataSource)) |
49 | - orm.NewBeeormEngine(config.Mysql{ | 49 | + NewBeeormEngine(config.Mysql{ |
50 | //AliasName: "default", | 50 | //AliasName: "default", |
51 | DataSource: dataSource, | 51 | DataSource: dataSource, |
52 | MaxIdle: 100, | 52 | MaxIdle: 100, |
@@ -104,3 +104,20 @@ var FilterBeforeStatic = func(ctx *context.Context) { | @@ -104,3 +104,20 @@ var FilterBeforeStatic = func(ctx *context.Context) { | ||
104 | ctx.ResponseWriter.Header().Add("Content-Type", "audio/mpeg") | 104 | ctx.ResponseWriter.Header().Add("Content-Type", "audio/mpeg") |
105 | } | 105 | } |
106 | } | 106 | } |
107 | + | ||
108 | +func NewBeeormEngine(conf config.Mysql) { | ||
109 | + aliasName := "default" | ||
110 | + if len(conf.AliasName) > 0 { | ||
111 | + aliasName = conf.AliasName | ||
112 | + } | ||
113 | + err := beeorm.RegisterDataBase(aliasName, "mysql", conf.DataSource) | ||
114 | + if err != nil { | ||
115 | + log.Error(err) | ||
116 | + } else { | ||
117 | + //log.Debug("open db address:",conf.DataSource) | ||
118 | + } | ||
119 | + beeorm.SetMaxIdleConns(aliasName, conf.MaxIdle) | ||
120 | + beeorm.SetMaxOpenConns(aliasName, conf.MaxOpen) | ||
121 | + //orm.DefaultTimeLoc = time.Local | ||
122 | + //orm.Debug = true | ||
123 | +} |
-
请 注册 或 登录 后发表评论