-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.go
54 lines (42 loc) · 1.01 KB
/
models.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package models
import (
"fmt"
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
"github.com/chenleji/nautilus/helper"
_ "github.com/go-sql-driver/mysql"
)
const (
DefaultDB = "default"
DriverName = "mysql"
)
func init() {
orm.Debug = false
conf := helper.GetConfInst().LoadConf()
dbURL := conf.DBUrl
dbPort := conf.DBPort
dbUser := conf.DBUser
dbPassword := conf.DBPwd
dbName := helper.Utils{}.GetAppName()
dataSource := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", dbUser, dbPassword, dbURL, dbPort, dbName)
maxIdle := 30
maxConn := 50
logs.Debug("dataSource:", dataSource)
orm.RegisterDriver(DriverName, orm.DRMySQL)
err := orm.RegisterDataBase(DefaultDB, DriverName, dataSource, maxIdle, maxConn)
if err != nil {
logs.Debug(err)
}
orm.RegisterModel(new(Model))
orm.RunSyncdb(DefaultDB, false, true)
}
type Model struct {
Id int
}
func DatabaseHealth() bool {
if _, err := orm.NewOrm().Raw("SHOW TABLES", ).Exec(); err != nil {
logs.Error(err)
return false
}
return true
}